Skip to content

Commit

Permalink
Added variable opening page based on time
Browse files Browse the repository at this point in the history
  • Loading branch information
kphanipavan committed Sep 29, 2023
1 parent ed9d694 commit c5b5c33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/models/initialPageIndexFunction.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ignore_for_file: file_names

int getInitialPageIndex() {
DateTime currentDate = DateTime.now();
late final int initPage;
if (currentDate.hour < 10) {
initPage = 0;
} else if (currentDate.hour >= 10 && currentDate.hour < 15) {
initPage = 1;
} else if (currentDate.hour >= 15 && currentDate.hour < 18) {
initPage = 2;
} else {
initPage = 3;
}
print(initPage);
return initPage;
}
3 changes: 2 additions & 1 deletion lib/views/homePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import "package:flutter/material.dart";
import "package:iiitb_menu/constants.dart";
import "package:iiitb_menu/models/globalModel.dart";
import "package:iiitb_menu/models/initialPageIndexFunction.dart";
import "package:iiitb_menu/views/menuListView.dart";
import "package:provider/provider.dart";

Expand All @@ -13,14 +14,14 @@ class HomePage extends StatelessWidget {
Widget build(BuildContext context) {
return SafeArea(
child: DefaultTabController(
initialIndex: getInitialPageIndex(),
length: 4,
child: Builder(builder: (context) {
TabController cont = DefaultTabController.of(context);
cont.addListener(() {
Provider.of<GlobalModel>(context, listen: false)
.setMenuTime(cont.index);
});
// }
return Consumer<GlobalModel>(
builder: (BuildContext context, GlobalModel data, Widget? child) {
return Scaffold(
Expand Down

0 comments on commit c5b5c33

Please sign in to comment.