-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.dart
More file actions
87 lines (74 loc) · 2.55 KB
/
app.dart
File metadata and controls
87 lines (74 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'core/providers/theme_provider.dart';
import 'core/theme/app_theme.dart';
import 'features/explorer/presentation/pages/explorer_page.dart';
import 'features/onboarding/data/onboarding_service.dart';
import 'features/onboarding/presentation/pages/onboarding_page.dart';
class XplorApp extends StatelessWidget {
const XplorApp({super.key});
@override
Widget build(BuildContext context) {
// Wrapper l'app avec ChangeNotifierProvider pour le ThemeProvider
return ChangeNotifierProvider(
create: (_) => ThemeProvider(),
child: const _XplorAppContent(),
);
}
}
/// Contenu de l'app qui écoute les changements de thème
class _XplorAppContent extends StatefulWidget {
const _XplorAppContent();
@override
State<_XplorAppContent> createState() => _XplorAppContentState();
}
class _XplorAppContentState extends State<_XplorAppContent> {
bool? _onboardingCompleted;
@override
void initState() {
super.initState();
_checkOnboarding();
}
Future<void> _checkOnboarding() async {
final completed = await OnboardingService.isOnboardingCompleted();
if (mounted) {
setState(() {
_onboardingCompleted = completed;
});
}
}
void _onOnboardingComplete() {
setState(() {
_onboardingCompleted = true;
});
}
@override
Widget build(BuildContext context) {
// Écouter les changements du ThemeProvider
final themeProvider = context.watch<ThemeProvider>();
// Afficher un loader pendant le chargement de la palette sauvegardée ou de l'état onboarding
if (themeProvider.isLoading || _onboardingCompleted == null) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Color(0xFF0A0A0A),
body: Center(child: CircularProgressIndicator(color: Colors.white)),
),
);
}
// Résoudre un bundle cohérent (Material + Shad) à partir de la palette courante
final themeBundle = AppTheme.current(themeProvider);
return ShadApp(
title: 'Xplor',
debugShowCheckedModeBanner: false,
theme: themeBundle.shad,
// Utiliser le thème avec palette ou le thème classique selon feature flag
materialThemeBuilder: (context, _) => themeBundle.material,
home: _onboardingCompleted!
? const ExplorerPage()
: OnboardingPage(onComplete: _onOnboardingComplete),
backgroundColor: themeBundle.background,
);
}
}