115 lines
2.9 KiB
Dart
115 lines
2.9 KiB
Dart
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 {
|
|
AgentNavigation({super.key});
|
|
|
|
static const items = [
|
|
{'label': 'Dashboard', 'icon': Icon(Icons.home)},
|
|
{'label': 'Notifications', 'icon': Icon(Icons.notifications)},
|
|
{'label': 'Account', 'icon': Icon(Icons.account_circle)},
|
|
];
|
|
|
|
final bottomDestinations = items
|
|
.map((element) => BottomNavigationBarItem(
|
|
icon: element["icon"] as Widget,
|
|
label: element["label"] as String,
|
|
))
|
|
.toList();
|
|
final railDestinations = items
|
|
.map((element) => NavigationRailDestination(
|
|
icon: element["icon"] as Widget,
|
|
label: Text(element["label"] as String),
|
|
))
|
|
.toList();
|
|
|
|
@override
|
|
State<AgentNavigation> createState() => _AgentNavigationState();
|
|
}
|
|
|
|
class _AgentNavigationState extends State<AgentNavigation> {
|
|
int _view = 0;
|
|
|
|
Future<void> 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) {
|
|
final isLargeScreen = MediaQuery.of(context).size.width > 640;
|
|
|
|
final content = Stack(
|
|
children: [
|
|
Offstage(
|
|
offstage: _view != 0,
|
|
child: const DashboardScreen(),
|
|
),
|
|
Offstage(
|
|
offstage: _view != 1,
|
|
child: const NotificationScreen(),
|
|
),
|
|
Offstage(
|
|
offstage: _view != 2,
|
|
child: const AccountScreen(),
|
|
)
|
|
],
|
|
);
|
|
|
|
if (isLargeScreen) {
|
|
return Row(children: <Widget>[
|
|
NavigationRail(
|
|
selectedIndex: _view,
|
|
groupAlignment: 0,
|
|
onDestinationSelected: (int index) {
|
|
setState(() {
|
|
_view = index;
|
|
});
|
|
},
|
|
labelType: NavigationRailLabelType.all,
|
|
destinations: widget.railDestinations,
|
|
),
|
|
const VerticalDivider(thickness: 1, width: 1),
|
|
Expanded(child: content),
|
|
]);
|
|
} else {
|
|
return Scaffold(
|
|
body: content,
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _view,
|
|
showUnselectedLabels: false,
|
|
items: widget.bottomDestinations,
|
|
onTap: (index) {
|
|
setState(() {
|
|
_view = index;
|
|
});
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|