🐛 Fix navigation state loss
This commit is contained in:
parent
1f415ec3ac
commit
e086aeebe4
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:solian/providers/auth.dart';
|
||||
import 'package:solian/providers/navigation.dart';
|
||||
import 'package:solian/router.dart';
|
||||
import 'package:solian/utils/timeago.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
@ -32,6 +33,7 @@ class SolianApp extends StatelessWidget {
|
||||
OverlayEntry(builder: (context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
Provider(create: (_) => NavigationProvider()),
|
||||
Provider(create: (_) => AuthProvider()),
|
||||
],
|
||||
child: child,
|
||||
|
3
lib/providers/navigation.dart
Normal file
3
lib/providers/navigation.dart
Normal file
@ -0,0 +1,3 @@
|
||||
class NavigationProvider {
|
||||
int selectedIndex = 0;
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:solian/providers/navigation.dart';
|
||||
import 'package:solian/router.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
@ -14,9 +16,21 @@ class _SolianNavigationDrawerState extends State<SolianNavigationDrawer> {
|
||||
|
||||
void _onSelect(String name, int idx) {
|
||||
setState(() => _selectedIndex = idx);
|
||||
context.read<NavigationProvider>().selectedIndex = idx;
|
||||
router.goNamed(name);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
Future.delayed(Duration.zero, () {
|
||||
setState(() {
|
||||
_selectedIndex = context.read<NavigationProvider>().selectedIndex;
|
||||
});
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final navigationItems = [
|
||||
|
Loading…
Reference in New Issue
Block a user