-
Notifications
You must be signed in to change notification settings - Fork 450
/
main.dart
50 lines (48 loc) · 2.04 KB
/
main.dart
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
//import 'package:auth_widget_builder/auth_widget_builder.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:starter_architecture_flutter_firebase/app/auth_widget.dart';
import 'package:starter_architecture_flutter_firebase/app/home/home_page.dart';
import 'package:starter_architecture_flutter_firebase/app/onboarding/onboarding_page.dart';
import 'package:starter_architecture_flutter_firebase/app/onboarding/onboarding_view_model.dart';
import 'package:starter_architecture_flutter_firebase/app/top_level_providers.dart';
import 'package:starter_architecture_flutter_firebase/app/sign_in/sign_in_page.dart';
import 'package:starter_architecture_flutter_firebase/routing/app_router.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:starter_architecture_flutter_firebase/services/shared_preferences_service.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
final sharedPreferences = await SharedPreferences.getInstance();
runApp(ProviderScope(
overrides: [
sharedPreferencesServiceProvider.overrideWithValue(
SharedPreferencesService(sharedPreferences),
),
],
child: MyApp(),
));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final firebaseAuth = context.read(firebaseAuthProvider);
return MaterialApp(
theme: ThemeData(primarySwatch: Colors.indigo),
debugShowCheckedModeBanner: false,
home: AuthWidget(
nonSignedInBuilder: (_) => Consumer(
builder: (context, watch, _) {
final didCompleteOnboarding =
watch(onboardingViewModelProvider.state);
return didCompleteOnboarding ? SignInPage() : OnboardingPage();
},
),
signedInBuilder: (_) => HomePage(),
),
onGenerateRoute: (settings) =>
AppRouter.onGenerateRoute(settings, firebaseAuth),
);
}
}