2024-02-08 07:19:37 +00:00
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
2024-02-07 17:25:58 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-02-10 12:08:25 +00:00
|
|
|
import 'package:goatagent/screens/account.dart';
|
|
|
|
import 'package:goatagent/screens/dashboard.dart';
|
|
|
|
import 'package:goatagent/screens/notifications.dart';
|
2024-02-07 17:25:58 +00:00
|
|
|
|
|
|
|
class AgentNavigation extends StatefulWidget {
|
2024-02-10 12:08:25 +00:00
|
|
|
const AgentNavigation({super.key});
|
2024-02-07 17:25:58 +00:00
|
|
|
|
|
|
|
static const items = [
|
|
|
|
NavigationDestination(
|
|
|
|
icon: Icon(Icons.home),
|
|
|
|
label: 'Dashboard',
|
|
|
|
),
|
2024-02-08 07:19:37 +00:00
|
|
|
NavigationDestination(
|
|
|
|
icon: Icon(Icons.notifications),
|
|
|
|
label: 'Notifications',
|
|
|
|
),
|
2024-02-07 17:25:58 +00:00
|
|
|
NavigationDestination(
|
|
|
|
icon: Icon(Icons.account_circle),
|
|
|
|
label: 'Account',
|
|
|
|
)
|
|
|
|
];
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AgentNavigation> createState() => _AgentNavigationState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AgentNavigationState extends State<AgentNavigation> {
|
2024-02-10 12:08:25 +00:00
|
|
|
int _view = 0;
|
2024-02-07 17:25:58 +00:00
|
|
|
|
2024-02-08 07:19:37 +00:00
|
|
|
Future<void> initMessage(BuildContext context) async {
|
|
|
|
void navigate() {
|
|
|
|
setState(() {
|
2024-02-10 12:08:25 +00:00
|
|
|
_view = 1;
|
2024-02-08 07:19:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoteMessage? initialMessage =
|
|
|
|
await FirebaseMessaging.instance.getInitialMessage();
|
|
|
|
|
|
|
|
if (initialMessage != null) {
|
|
|
|
navigate();
|
|
|
|
}
|
|
|
|
|
|
|
|
FirebaseMessaging.onMessageOpenedApp.listen((event) {
|
|
|
|
navigate();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
initMessage(context);
|
|
|
|
}
|
|
|
|
|
2024-02-07 17:25:58 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-02-10 12:08:25 +00:00
|
|
|
return Scaffold(
|
|
|
|
body: Stack(
|
|
|
|
children: [
|
|
|
|
Offstage(
|
|
|
|
offstage: _view != 0,
|
|
|
|
child: const DashboardScreen(),
|
|
|
|
),
|
|
|
|
Offstage(
|
|
|
|
offstage: _view != 1,
|
|
|
|
child: const NotificationScreen(),
|
|
|
|
),
|
|
|
|
Offstage(
|
|
|
|
offstage: _view != 2,
|
|
|
|
child: const AccountScreen(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
bottomNavigationBar: NavigationBar(
|
|
|
|
selectedIndex: _view,
|
|
|
|
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
|
|
|
|
destinations: AgentNavigation.items,
|
|
|
|
onDestinationSelected: (index) {
|
|
|
|
setState(() {
|
|
|
|
_view = index;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
2024-02-07 17:25:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|