1-) FLUTTER - sonsuz kategori kullanımı infinite use of categories
flutter pub add stack
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:rokethizmet/ekhizmetler/statiksinif.dart';
import 'package:theme_provider/theme_provider.dart';
import 'package:stack/stack.dart' as st2;
class IlanOlusturPage extends StatefulWidget {
const IlanOlusturPage({Key? key}) : super(key: key);
@override
State<IlanOlusturPage> createState() => IlanOlusturPageState();
}
class Kategori {
late int id;
late int masterId;
late String kategoriAd;
}
class IlanOlusturPageState extends State<IlanOlusturPage> {
@override
void initState() {
// TODO: implement initState
super.initState();
kategoriAdd(1, 1, "yazılım");
kategoriAdd(2, 1, "c#");
kategoriAdd(3, 1, "java");
kategoriAdd(4, 1, "pyhton");
kategoriAdd(5, 2, "mvc");
kategoriAdd(6, 2, "first code");
kategoriAdd(7, 3, "entity");
kategoriAdd(8, 8, "inşaat");
kategoriAdd(9, 8, "iç mimar");
anaKategoriList();
}
st2.Stack<int> stack = st2.Stack<int>();
void anaKategoriList() {
stack.push(-1);
kategoriList = kategoriListSabit
.where((element) => element.id == element.masterId)
.toList();
setState(() {});
}
List<Kategori> kategoriListele(int id) {
stack.push(id);
kategoriList = kategoriListSabit
.where((element) =>
id == element.masterId && element.id != element.masterId)
.toList();
setState(() {});
return kategoriList;
}
List<Kategori> kategoriList = [];
List<Kategori> kategoriListSabit = [];
void kategoriAdd(int id, int masterId, String ad) {
Kategori kategori = new Kategori();
kategori.id = id;
kategori.masterId = masterId;
kategori.kategoriAd = ad;
kategoriListSabit.add(kategori);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Center(
child: Container(
width: kIsWeb ? 600.0 : double.infinity,
child: Scaffold(
appBar: AppBar(
title: Text("İlan Oluştur"),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ilanOlusturContent(),
],
),
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked,
floatingActionButton: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FloatingActionButton(
onPressed: () {
int node = stack.pop();
if (node == -1) {
//Navigator.pop(context);
stack.push(-1);
return;
}
node = stack.pop();
if(node==-1){
anaKategoriList();
}else{
kategoriListele(node);
}
},
child: Icon(Icons.navigate_before, color: getTextColor()),
backgroundColor: getBackColor(),
heroTag: "btn1",
),
// FloatingActionButton(
// onPressed: () {},
// child: Icon(
// Icons.navigate_next,
// color: getTextColor(),
// ),
// backgroundColor: getBackColor(),
// heroTag: "btn2",
// )
],
),
)),
),
),
);
}
Color getTextColor() {
return StatikSinif.isDarkModeEnabled == true
? Colors.white
: Colors.black54;
}
Color getBackColor() {
return ThemeProvider.themeOf(context).data.bottomAppBarColor;
}
Padding ilanOlusturContent() {
return Padding(
padding: EdgeInsets.only(left: 10, right: 10),
child: Material(
elevation: 17,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(15.0),
)),
child: Padding(
padding: EdgeInsets.all(15),
child: buildTreeContent(),
),
),
);
}
Widget buildTreeContent() {
return Container(
child: GridView.builder(
controller: new ScrollController(keepScrollOffset: false),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: kategoriList.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisExtent: 75, // yükseklik demek
),
itemBuilder: (BuildContext contex, int index) {
Kategori kategori = kategoriList[index];
return Container(
child: Padding(
padding: EdgeInsets.only(top: 5),
child: Container(
child: MaterialButton(
elevation: 17,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
onPressed: () {
kategoriListele(kategori.id);
},
color: ThemeProvider.themeOf(context).data.bottomAppBarColor,
textColor: ThemeProvider.themeOf(context)
.data
.bottomSheetTheme
.backgroundColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
kategori.kategoriAd,
style: TextStyle(fontSize: 20),
),
Icon(Icons.chevron_right_outlined)
],
),
),
),
),
);
},
),
);
}
}