2024-11-13 16:08:09 +00:00
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
2024-11-13 16:20:59 +00:00
|
|
|
|
import 'package:responsive_framework/responsive_framework.dart';
|
2024-11-13 16:08:09 +00:00
|
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
|
|
|
import 'package:surface/providers/navigation.dart';
|
|
|
|
|
|
|
|
|
|
class AppNavigationDrawer extends StatefulWidget {
|
2024-11-14 14:21:13 +00:00
|
|
|
|
final double? elevation;
|
|
|
|
|
const AppNavigationDrawer({super.key, this.elevation});
|
2024-11-13 16:08:09 +00:00
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<AppNavigationDrawer> createState() => _AppNavigationDrawerState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
context
|
|
|
|
|
.read<NavigationProvider>()
|
|
|
|
|
.autoDetectIndex(GoRouter.maybeOf(context));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final nav = context.watch<NavigationProvider>();
|
|
|
|
|
|
2024-11-13 16:20:59 +00:00
|
|
|
|
final backgroundColor = ResponsiveBreakpoints.of(context).largerThan(MOBILE)
|
|
|
|
|
? Theme.of(context).colorScheme.surface
|
|
|
|
|
: null;
|
|
|
|
|
|
2024-11-13 16:08:09 +00:00
|
|
|
|
return ListenableBuilder(
|
|
|
|
|
listenable: nav,
|
|
|
|
|
builder: (context, _) {
|
|
|
|
|
final destinations = [
|
|
|
|
|
...nav.destinations.where((ele) => ele.isPinned),
|
|
|
|
|
...nav.destinations.where((ele) => !ele.isPinned),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return NavigationDrawer(
|
2024-11-14 14:21:13 +00:00
|
|
|
|
elevation: widget.elevation,
|
2024-11-13 16:20:59 +00:00
|
|
|
|
backgroundColor: backgroundColor,
|
2024-11-13 16:08:09 +00:00
|
|
|
|
selectedIndex: nav.currentIndex,
|
|
|
|
|
children: [
|
|
|
|
|
Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text('Solar Network').bold(),
|
2024-11-14 15:21:30 +00:00
|
|
|
|
Text('Canary Preview 2.0α').fontSize(12).textColor(
|
2024-11-13 16:08:09 +00:00
|
|
|
|
Theme.of(context).colorScheme.onSurface.withOpacity(0.5)),
|
|
|
|
|
],
|
|
|
|
|
).padding(
|
|
|
|
|
horizontal: 32,
|
2024-11-14 15:21:30 +00:00
|
|
|
|
top: MediaQuery.of(context).padding.top > 16 ? 8 : 16,
|
2024-11-13 16:20:59 +00:00
|
|
|
|
bottom: 16,
|
2024-11-13 16:08:09 +00:00
|
|
|
|
),
|
|
|
|
|
...destinations.where((ele) => ele.isPinned).map((ele) {
|
|
|
|
|
return NavigationDrawerDestination(
|
|
|
|
|
icon: ele.icon,
|
|
|
|
|
label: Text(ele.label).tr(),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
const Divider(),
|
|
|
|
|
...destinations.where((ele) => !ele.isPinned).map((ele) {
|
|
|
|
|
return NavigationDrawerDestination(
|
|
|
|
|
icon: ele.icon,
|
|
|
|
|
label: Text(ele.label).tr(),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
onDestinationSelected: (idx) {
|
|
|
|
|
nav.setIndex(idx);
|
|
|
|
|
GoRouter.of(context).goNamed(destinations[idx].screen);
|
|
|
|
|
Scaffold.of(context).closeDrawer();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|