Fix title not changing when swiped
This commit is contained in:
@@ -16,84 +16,97 @@ class HomePage extends StatelessWidget {
|
||||
return SafeArea(
|
||||
child: DefaultTabController(
|
||||
length: 4,
|
||||
child: Consumer<GlobalModel>(
|
||||
builder: (BuildContext context, GlobalModel data, Widget? child) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Daily ${data.menuTime} Menu"),
|
||||
bottom: TabBar(
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
indicator: const UnderlineTabIndicator(
|
||||
insets: EdgeInsets.fromLTRB(10, 3, 10, 3)),
|
||||
onTap: (int index) {
|
||||
Provider.of<GlobalModel>(context, listen: false)
|
||||
.setMenuTime(index);
|
||||
},
|
||||
tabs: const [
|
||||
Tab(icon: Icon(Icons.breakfast_dining_outlined)),
|
||||
Tab(icon: Icon(Icons.lunch_dining_outlined)),
|
||||
Tab(icon: Icon(Icons.coffee_outlined)),
|
||||
Tab(icon: Icon(Icons.dinner_dining_outlined))
|
||||
]),
|
||||
actions: [
|
||||
InkWell(
|
||||
child: Builder(builder: (context) {
|
||||
TabController cont = DefaultTabController.of(context);
|
||||
// print("Rebuilt");
|
||||
// if (!cont.hasListeners) {
|
||||
// print("Adding callback");
|
||||
cont.addListener(() {
|
||||
// print("Called Callback");
|
||||
Provider.of<GlobalModel>(context, listen: false)
|
||||
.setMenuTime(cont.index);
|
||||
});
|
||||
// }
|
||||
return Consumer<GlobalModel>(
|
||||
builder: (BuildContext context, GlobalModel data, Widget? child) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Daily ${data.menuTime} Menu"),
|
||||
bottom: TabBar(
|
||||
controller: cont,
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
onTap: () {
|
||||
data.decrDate();
|
||||
indicator: const UnderlineTabIndicator(
|
||||
insets: EdgeInsets.fromLTRB(10, 3, 10, 3)),
|
||||
onTap: (int index) {
|
||||
data.setMenuTime(index);
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.arrow_left_rounded,
|
||||
size: 30,
|
||||
)),
|
||||
InkWell(
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
onLongPress: () {
|
||||
showDatePicker(
|
||||
context: context,
|
||||
initialDate: data.currentDate,
|
||||
firstDate:
|
||||
data.currentDate.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,
|
||||
tabs: const [
|
||||
Tab(icon: Icon(Icons.breakfast_dining_outlined)),
|
||||
Tab(icon: Icon(Icons.lunch_dining_outlined)),
|
||||
Tab(icon: Icon(Icons.coffee_outlined)),
|
||||
Tab(icon: Icon(Icons.dinner_dining_outlined))
|
||||
]),
|
||||
actions: [
|
||||
InkWell(
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
onTap: () {
|
||||
data.decrDate();
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.arrow_left_rounded,
|
||||
size: 30,
|
||||
)),
|
||||
InkWell(
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
onLongPress: () {
|
||||
showDatePicker(
|
||||
context: context,
|
||||
initialDate: data.currentDate,
|
||||
firstDate: data.currentDate
|
||||
.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(
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
onTap: () {
|
||||
data.incrDate();
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.arrow_right_rounded,
|
||||
size: 30,
|
||||
)),
|
||||
],
|
||||
),
|
||||
body: TabBarView(
|
||||
children: data.menuAvailable
|
||||
? const [
|
||||
MenuListView(menuType: "bf"),
|
||||
MenuListView(menuType: "ln"),
|
||||
MenuListView(menuType: "sk"),
|
||||
MenuListView(menuType: "dn"),
|
||||
]
|
||||
: [
|
||||
noMenuWidget,
|
||||
noMenuWidget,
|
||||
noMenuWidget,
|
||||
noMenuWidget,
|
||||
]),
|
||||
);
|
||||
InkWell(
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
onTap: () {
|
||||
data.incrDate();
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.arrow_right_rounded,
|
||||
size: 30,
|
||||
)),
|
||||
],
|
||||
),
|
||||
body: TabBarView(
|
||||
controller: cont,
|
||||
children: data.menuAvailable
|
||||
? const [
|
||||
MenuListView(menuType: "bf"),
|
||||
MenuListView(menuType: "ln"),
|
||||
MenuListView(menuType: "sk"),
|
||||
MenuListView(menuType: "dn"),
|
||||
]
|
||||
: [
|
||||
noMenuWidget,
|
||||
noMenuWidget,
|
||||
noMenuWidget,
|
||||
noMenuWidget,
|
||||
]),
|
||||
);
|
||||
});
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user