96 lines
2.8 KiB
Dart
96 lines
2.8 KiB
Dart
import 'package:auto_route/auto_route.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:furman_now/src/routes/index.gr.dart';
|
|
|
|
class MainLayout extends StatefulWidget {
|
|
const MainLayout({
|
|
Key? key,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<MainLayout> createState() => _MainLayoutState();
|
|
}
|
|
|
|
class _MainLayoutState extends State<MainLayout> {
|
|
DateTime oldTime = DateTime.now();
|
|
DateTime newTime = DateTime.now();
|
|
|
|
void showSnackBar() {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
behavior: SnackBarBehavior.floating,
|
|
duration: Duration(milliseconds: 600),
|
|
margin: EdgeInsets.only(bottom: 2, right: 2, left: 2),
|
|
content: Text('Tap back button again to exit'),
|
|
),
|
|
);
|
|
}
|
|
|
|
void hideSnackBar() {
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AutoTabsScaffold(
|
|
routes: const [
|
|
HomeRoute(),
|
|
MapRoute(),
|
|
StudentIdRoute(),
|
|
EventsRoute(),
|
|
InfoRoute(),
|
|
],
|
|
bottomNavigationBuilder: (_, tabsRouter) {
|
|
return WillPopScope(
|
|
onWillPop: () async {
|
|
if (tabsRouter.canNavigateBack) {
|
|
tabsRouter.navigateBack();
|
|
return false;
|
|
} else {
|
|
// if can't navigate back then we're probably trying to exit
|
|
newTime = DateTime.now();
|
|
int difference = newTime.difference(oldTime).inMilliseconds;
|
|
oldTime = newTime;
|
|
if (difference < 1000) {
|
|
hideSnackBar();
|
|
return true;
|
|
} else {
|
|
showSnackBar();
|
|
return false;
|
|
}
|
|
}
|
|
},
|
|
child: BottomNavigationBar(
|
|
items: const <BottomNavigationBarItem>[
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.home),
|
|
label: 'Home',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.map),
|
|
label: 'Map',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.perm_identity),
|
|
label: 'Meal Card',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.calendar_month),
|
|
label: 'Events',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.info_outline),
|
|
label: 'Info',
|
|
),
|
|
],
|
|
currentIndex: tabsRouter.activeIndex,
|
|
selectedItemColor: Theme.of(context).primaryColor,
|
|
unselectedItemColor: Colors.grey[600],
|
|
onTap: tabsRouter.setActiveIndex,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} |