Fix title not changing when swiped

This commit is contained in:
2023-09-10 14:17:35 +05:30
parent 99ac404ecc
commit e2fece76a6

View File

@@ -16,84 +16,97 @@ class HomePage extends StatelessWidget {
return SafeArea( return SafeArea(
child: DefaultTabController( child: DefaultTabController(
length: 4, length: 4,
child: Consumer<GlobalModel>( child: Builder(builder: (context) {
builder: (BuildContext context, GlobalModel data, Widget? child) { TabController cont = DefaultTabController.of(context);
return Scaffold( // print("Rebuilt");
appBar: AppBar( // if (!cont.hasListeners) {
title: Text("Daily ${data.menuTime} Menu"), // print("Adding callback");
bottom: TabBar( cont.addListener(() {
splashFactory: NoSplash.splashFactory, // print("Called Callback");
indicator: const UnderlineTabIndicator( Provider.of<GlobalModel>(context, listen: false)
insets: EdgeInsets.fromLTRB(10, 3, 10, 3)), .setMenuTime(cont.index);
onTap: (int index) { });
Provider.of<GlobalModel>(context, listen: false) // }
.setMenuTime(index); return Consumer<GlobalModel>(
}, builder: (BuildContext context, GlobalModel data, Widget? child) {
tabs: const [ return Scaffold(
Tab(icon: Icon(Icons.breakfast_dining_outlined)), appBar: AppBar(
Tab(icon: Icon(Icons.lunch_dining_outlined)), title: Text("Daily ${data.menuTime} Menu"),
Tab(icon: Icon(Icons.coffee_outlined)), bottom: TabBar(
Tab(icon: Icon(Icons.dinner_dining_outlined)) controller: cont,
]),
actions: [
InkWell(
splashFactory: NoSplash.splashFactory, splashFactory: NoSplash.splashFactory,
onTap: () { indicator: const UnderlineTabIndicator(
data.decrDate(); insets: EdgeInsets.fromLTRB(10, 3, 10, 3)),
onTap: (int index) {
data.setMenuTime(index);
}, },
child: const Icon( tabs: const [
Icons.arrow_left_rounded, Tab(icon: Icon(Icons.breakfast_dining_outlined)),
size: 30, Tab(icon: Icon(Icons.lunch_dining_outlined)),
)), Tab(icon: Icon(Icons.coffee_outlined)),
InkWell( Tab(icon: Icon(Icons.dinner_dining_outlined))
splashFactory: NoSplash.splashFactory, ]),
onLongPress: () { actions: [
showDatePicker( InkWell(
context: context, splashFactory: NoSplash.splashFactory,
initialDate: data.currentDate, onTap: () {
firstDate: data.decrDate();
data.currentDate.add(const Duration(days: -30)), },
lastDate: child: const Icon(
data.currentDate.add(const Duration(days: 30))) Icons.arrow_left_rounded,
.then((value) { size: 30,
data.setDateToADay(value ?? data.currentDate); )),
}); InkWell(
}, splashFactory: NoSplash.splashFactory,
onTap: () { onLongPress: () {
data.setDateToADay(); showDatePicker(
}, context: context,
child: Center( initialDate: data.currentDate,
child: Text( firstDate: data.currentDate
data.date, .add(const Duration(days: -30)),
lastDate: data.currentDate
.add(const Duration(days: 30)))
.then((value) {
data.setDateToADay(value ?? data.currentDate);
});
},
onTap: () {
data.setDateToADay();
},
child: Center(
child: Text(
data.date,
),
), ),
), ),
), InkWell(
InkWell( splashFactory: NoSplash.splashFactory,
splashFactory: NoSplash.splashFactory, onTap: () {
onTap: () { data.incrDate();
data.incrDate(); },
}, child: const Icon(
child: const Icon( Icons.arrow_right_rounded,
Icons.arrow_right_rounded, size: 30,
size: 30, )),
)), ],
], ),
), body: TabBarView(
body: TabBarView( controller: cont,
children: data.menuAvailable children: data.menuAvailable
? const [ ? const [
MenuListView(menuType: "bf"), MenuListView(menuType: "bf"),
MenuListView(menuType: "ln"), MenuListView(menuType: "ln"),
MenuListView(menuType: "sk"), MenuListView(menuType: "sk"),
MenuListView(menuType: "dn"), MenuListView(menuType: "dn"),
] ]
: [ : [
noMenuWidget, noMenuWidget,
noMenuWidget, noMenuWidget,
noMenuWidget, noMenuWidget,
noMenuWidget, noMenuWidget,
]), ]),
); );
});
}), }),
), ),
); );