2022-11-19 03:49:11 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2022-12-10 16:44:13 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2022-11-19 03:49:11 +00:00
|
|
|
|
|
|
|
import '../routes.dart';
|
2022-12-10 16:44:13 +00:00
|
|
|
import '../services/notifications_manager.dart';
|
2022-11-19 03:49:11 +00:00
|
|
|
|
|
|
|
enum NavBarButtons {
|
2022-12-08 19:23:11 +00:00
|
|
|
timelines,
|
2022-11-19 03:49:11 +00:00
|
|
|
notifications,
|
|
|
|
contacts,
|
2023-01-19 17:50:11 +00:00
|
|
|
menu,
|
2022-11-19 03:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class AppBottomNavBar extends StatelessWidget {
|
|
|
|
final NavBarButtons currentButton;
|
|
|
|
|
|
|
|
const AppBottomNavBar({super.key, required this.currentButton});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-12-10 16:44:13 +00:00
|
|
|
final notificationManager = context.watch<NotificationsManager>();
|
2022-12-30 15:37:01 +00:00
|
|
|
final hasNotifications =
|
|
|
|
notificationManager.notifications.where((n) => !n.dismissed).isNotEmpty;
|
2022-11-19 03:49:11 +00:00
|
|
|
return BottomNavigationBar(
|
|
|
|
onTap: (index) {
|
|
|
|
final newButton = _indexToButton(index);
|
|
|
|
if (newButton == currentButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (newButton) {
|
2022-12-08 19:23:11 +00:00
|
|
|
case NavBarButtons.timelines:
|
2022-11-19 03:49:11 +00:00
|
|
|
Navigator.of(context).popUntil((route) {
|
2022-12-08 19:23:11 +00:00
|
|
|
return route.settings.name == ScreenPaths.timelines;
|
2022-11-19 03:49:11 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case NavBarButtons.notifications:
|
|
|
|
context.pushNamed(ScreenPaths.notifications);
|
|
|
|
break;
|
|
|
|
case NavBarButtons.contacts:
|
2022-12-15 03:27:30 +00:00
|
|
|
context.pushNamed(ScreenPaths.contacts);
|
2022-11-19 03:49:11 +00:00
|
|
|
break;
|
2023-01-19 17:50:11 +00:00
|
|
|
case NavBarButtons.menu:
|
|
|
|
context.pushNamed(ScreenPaths.menu);
|
2022-12-14 02:06:10 +00:00
|
|
|
break;
|
2022-11-19 03:49:11 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
type: BottomNavigationBarType.fixed,
|
|
|
|
currentIndex: _buttonToIndex(currentButton),
|
2023-01-20 01:37:35 +00:00
|
|
|
items: _menuItems(context, hasNotifications),
|
2022-11-19 03:49:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int _buttonToIndex(NavBarButtons button) {
|
|
|
|
switch (button) {
|
2022-12-08 19:23:11 +00:00
|
|
|
case NavBarButtons.timelines:
|
2022-11-19 03:49:11 +00:00
|
|
|
return 0;
|
|
|
|
case NavBarButtons.notifications:
|
|
|
|
return 1;
|
2023-01-19 17:50:11 +00:00
|
|
|
case NavBarButtons.contacts:
|
2022-11-19 03:49:11 +00:00
|
|
|
return 2;
|
2023-01-19 17:50:11 +00:00
|
|
|
case NavBarButtons.menu:
|
2022-11-19 03:49:11 +00:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NavBarButtons _indexToButton(int index) {
|
|
|
|
if (index == 0) {
|
2022-12-08 19:23:11 +00:00
|
|
|
return NavBarButtons.timelines;
|
2022-11-19 03:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index == 1) {
|
|
|
|
return NavBarButtons.notifications;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == 2) {
|
2022-12-14 02:06:10 +00:00
|
|
|
return NavBarButtons.contacts;
|
|
|
|
}
|
|
|
|
|
2023-01-19 17:50:11 +00:00
|
|
|
if (index == 3) {
|
|
|
|
return NavBarButtons.menu;
|
2022-11-19 03:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw ArgumentError('$index has no button type');
|
|
|
|
}
|
|
|
|
|
2023-01-20 01:37:35 +00:00
|
|
|
List<BottomNavigationBarItem> _menuItems(
|
|
|
|
BuildContext context, bool hasNotifications) {
|
2022-12-10 16:44:13 +00:00
|
|
|
return [
|
|
|
|
const BottomNavigationBarItem(
|
2022-12-08 19:23:11 +00:00
|
|
|
label: 'Timelines',
|
2022-11-19 03:49:11 +00:00
|
|
|
icon: Icon(Icons.home_outlined),
|
|
|
|
activeIcon: Icon(Icons.home_filled),
|
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
label: 'Notifications',
|
2022-12-10 16:44:13 +00:00
|
|
|
icon: Icon(hasNotifications
|
|
|
|
? Icons.notifications_active_outlined
|
|
|
|
: Icons.notifications_none_outlined),
|
|
|
|
activeIcon: Icon(hasNotifications
|
|
|
|
? Icons.notifications_active
|
|
|
|
: Icons.notifications),
|
2022-11-19 03:49:11 +00:00
|
|
|
),
|
2022-12-10 16:44:13 +00:00
|
|
|
const BottomNavigationBarItem(
|
2022-11-19 03:49:11 +00:00
|
|
|
label: 'Contacts',
|
|
|
|
icon: Icon(Icons.people_outline),
|
|
|
|
activeIcon: Icon(Icons.people_sharp),
|
|
|
|
),
|
2022-12-10 16:44:13 +00:00
|
|
|
const BottomNavigationBarItem(
|
2023-01-19 17:50:11 +00:00
|
|
|
label: 'Menu',
|
|
|
|
icon: Icon(Icons.menu),
|
|
|
|
activeIcon: Icon(Icons.menu_open),
|
2022-11-19 03:49:11 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|