fix: stable GoRouter instance + spinner on dashboard initial load
This commit is contained in:
parent
1a859fc5b9
commit
d091b4412d
|
|
@ -16,7 +16,6 @@ import 'screens/ventes_screen.dart';
|
|||
import 'screens/achats_screen.dart';
|
||||
import 'screens/production_screen.dart';
|
||||
import 'screens/stock_screen.dart';
|
||||
import 'widgets/app_drawer.dart';
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
|
|
@ -35,15 +34,28 @@ void main() {
|
|||
);
|
||||
}
|
||||
|
||||
class RayhanApp extends StatelessWidget {
|
||||
class RayhanApp extends StatefulWidget {
|
||||
const RayhanApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authProvider = context.watch<AuthProvider>();
|
||||
State<RayhanApp> createState() => _RayhanAppState();
|
||||
}
|
||||
|
||||
final router = GoRouter(
|
||||
class _RayhanAppState extends State<RayhanApp> {
|
||||
late final GoRouter _router;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final authProvider = context.read<AuthProvider>();
|
||||
_router = GoRouter(
|
||||
initialLocation: '/login',
|
||||
refreshListenable: authProvider,
|
||||
redirect: (context, state) {
|
||||
final loggedIn = authProvider.isAuthenticated;
|
||||
final onLogin = state.matchedLocation == '/login';
|
||||
|
|
@ -61,7 +73,16 @@ class RayhanApp extends StatelessWidget {
|
|||
GoRoute(path: '/stock', builder: (_, __) => const StockScreen()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_router.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
title: 'Rayhan ERP',
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
|
@ -73,35 +94,7 @@ class RayhanApp extends StatelessWidget {
|
|||
useMaterial3: true,
|
||||
fontFamily: 'Roboto',
|
||||
),
|
||||
routerConfig: router,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PlaceholderScreen extends StatelessWidget {
|
||||
final String title;
|
||||
final String route;
|
||||
const _PlaceholderScreen({required this.title, required this.route});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(title)),
|
||||
drawer: AppDrawer(currentRoute: route),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.construction_outlined, size: 64, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
Text('Module $title',
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 8),
|
||||
Text('En cours de développement',
|
||||
style: TextStyle(color: Colors.grey[600])),
|
||||
],
|
||||
),
|
||||
),
|
||||
routerConfig: _router,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
|||
}
|
||||
|
||||
final kpi = provider.kpi;
|
||||
if (kpi == null) return const SizedBox.shrink();
|
||||
if (kpi == null) return const Center(child: CircularProgressIndicator());
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () => context.read<DashboardProvider>().load(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue