import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'package:goatagent/screens/account.dart'; import 'package:goatagent/screens/dashboard.dart'; import 'package:goatagent/screens/notifications.dart'; class AgentNavigation extends StatefulWidget { const AgentNavigation({super.key}); 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', ) ]; @override State createState() => _AgentNavigationState(); } class _AgentNavigationState extends State { int _view = 0; Future initMessage(BuildContext context) async { void navigate() { setState(() { _view = 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 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; }); }, ), ); } }