75 lines
1.7 KiB
Dart
75 lines
1.7 KiB
Dart
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
class AgentNavigation extends StatefulWidget {
|
|
const AgentNavigation({super.key, required this.router});
|
|
|
|
final GoRouter router;
|
|
|
|
static const items = [
|
|
NavigationDestination(
|
|
icon: Icon(Icons.home),
|
|
label: 'Dashboard',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.notifications),
|
|
label: 'Notifications',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.account_circle),
|
|
label: 'Account',
|
|
)
|
|
];
|
|
|
|
static const destinations = ["/", "/notifications", "/account"];
|
|
|
|
@override
|
|
State<AgentNavigation> createState() => _AgentNavigationState();
|
|
}
|
|
|
|
class _AgentNavigationState extends State<AgentNavigation> {
|
|
int _selected = 0;
|
|
|
|
Future<void> initMessage(BuildContext context) async {
|
|
void navigate() {
|
|
widget.router.push("/notifications");
|
|
setState(() {
|
|
_selected = 1;
|
|
});
|
|
}
|
|
|
|
RemoteMessage? initialMessage =
|
|
await FirebaseMessaging.instance.getInitialMessage();
|
|
|
|
if (initialMessage != null) {
|
|
navigate();
|
|
}
|
|
|
|
FirebaseMessaging.onMessageOpenedApp.listen((event) {
|
|
navigate();
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
initMessage(context);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return NavigationBar(
|
|
selectedIndex: _selected,
|
|
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
|
|
destinations: AgentNavigation.items,
|
|
onDestinationSelected: (index) {
|
|
widget.router.push(AgentNavigation.destinations[index]);
|
|
setState(() {
|
|
_selected = index;
|
|
});
|
|
},
|
|
);
|
|
}
|
|
}
|