Solian/lib/widgets/navigation_drawer.dart

86 lines
2.3 KiB
Dart
Raw Normal View History

2024-04-12 16:38:20 +00:00
import 'package:flutter/material.dart';
2024-04-13 16:10:22 +00:00
import 'package:provider/provider.dart';
import 'package:solian/providers/navigation.dart';
2024-04-12 16:38:20 +00:00
import 'package:solian/router.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class SolianNavigationDrawer extends StatefulWidget {
const SolianNavigationDrawer({super.key});
@override
State<SolianNavigationDrawer> createState() => _SolianNavigationDrawerState();
}
class _SolianNavigationDrawerState extends State<SolianNavigationDrawer> {
var _selectedIndex = 0;
void _onSelect(String name, int idx) {
setState(() => _selectedIndex = idx);
2024-04-13 16:10:22 +00:00
context.read<NavigationProvider>().selectedIndex = idx;
2024-04-12 16:38:20 +00:00
router.goNamed(name);
}
2024-04-13 16:10:22 +00:00
@override
void initState() {
Future.delayed(Duration.zero, () {
setState(() {
_selectedIndex = context.read<NavigationProvider>().selectedIndex;
});
});
super.initState();
}
2024-04-12 16:38:20 +00:00
@override
Widget build(BuildContext context) {
final navigationItems = [
(
NavigationDrawerDestination(
icon: const Icon(Icons.explore),
label: Text(AppLocalizations.of(context)!.explore),
),
2024-05-01 16:49:38 +00:00
'explore',
2024-04-12 16:38:20 +00:00
),
2024-04-16 14:29:58 +00:00
(
NavigationDrawerDestination(
icon: const Icon(Icons.send),
label: Text(AppLocalizations.of(context)!.chat),
),
2024-05-01 16:49:38 +00:00
'chat',
2024-04-16 14:29:58 +00:00
),
(
NavigationDrawerDestination(
icon: const Icon(Icons.account_circle),
label: Text(AppLocalizations.of(context)!.account),
),
2024-05-01 16:49:38 +00:00
'account',
),
2024-04-12 16:38:20 +00:00
];
return NavigationDrawer(
selectedIndex: _selectedIndex,
onDestinationSelected: (int idx) {
final element = navigationItems[idx];
_onSelect(element.$2, idx);
},
children: [
Padding(
padding: const EdgeInsets.fromLTRB(28, 16, 16, 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
2024-05-01 16:49:38 +00:00
Image.asset('assets/logo.png', width: 26, height: 26),
2024-04-12 16:38:20 +00:00
const SizedBox(width: 10),
Text(
2024-04-29 12:22:06 +00:00
AppLocalizations.of(context)!.appName,
2024-04-12 16:38:20 +00:00
style: const TextStyle(fontWeight: FontWeight.w900),
),
],
),
),
...navigationItems.map((x) => x.$1)
],
);
}
}