forked from X-Wei/flutter_catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_main_app.dart
57 lines (50 loc) · 1.49 KB
/
my_main_app.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
51
52
53
54
55
56
57
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import './constants.dart' show kAppIcon;
import './my_app_routes.dart' show kAppRoutingTable;
import './my_app_settings.dart';
import './themes.dart';
class MyMainApp extends StatelessWidget {
const MyMainApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return FutureBuilder<SharedPreferences>(
future: SharedPreferences.getInstance(),
builder:
(BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
if (!snapshot.hasData) {
return _MySplashScreen();
}
return ChangeNotifierProvider<MyAppSettings>.value(
value: MyAppSettings(snapshot.data),
child: _MyMainApp(),
);
},
);
}
}
class _MySplashScreen extends StatelessWidget {
const _MySplashScreen({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
constraints: BoxConstraints.expand(),
color: Colors.white,
child: Center(child: kAppIcon),
);
}
}
class _MyMainApp extends StatelessWidget {
const _MyMainApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Catalog',
theme: Provider.of<MyAppSettings>(context).isDarkMode
? kDartTheme
: kLightTheme,
routes: kAppRoutingTable,
);
}
}