forked from Sky24n/flutter_wanandroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
96 lines (85 loc) · 2.43 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
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
88
89
90
91
92
93
94
95
96
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_wanandroid/common/component_index.dart';
import 'package:flutter_wanandroid/data/net/dio_util.dart';
import 'package:flutter_wanandroid/ui/pages/main_page.dart';
import 'package:flutter_wanandroid/ui/pages/page_index.dart';
void main() => runApp(BlocProvider<ApplicationBloc>(
bloc: ApplicationBloc(),
child: BlocProvider(child: MyApp(), bloc: MainBloc()),
));
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyAppState();
}
}
class MyAppState extends State<MyApp> {
Locale _locale;
Color _themeColor = Colours.app_main;
@override
void initState() {
super.initState();
setLocalizedValues(localizedValues);
_init();
_initAsync();
_initListener();
}
void _init() {
// DioUtil.openDebug();
Options options = DioUtil.getDefOptions();
options.baseUrl = Constant.SERVER_ADDRESS;
HttpConfig config = new HttpConfig(options: options);
DioUtil().setConfig(config);
}
void _initAsync() async {
await SpUtil.getInstance();
if (!mounted) return;
_loadLocale();
}
void _initListener() {
final ApplicationBloc bloc = BlocProvider.of<ApplicationBloc>(context);
bloc.appEventStream.listen((value) {
_loadLocale();
});
}
void _loadLocale() {
setState(() {
LanguageModel model = SpHelper.getLanguageModel();
if (model != null) {
_locale = new Locale(model.languageCode, model.countryCode);
} else {
_locale = null;
}
String _colorKey = SpHelper.getThemeColor();
if (themeColorMap[_colorKey] != null)
_themeColor = themeColorMap[_colorKey];
});
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
routes: {
'/MainPage': (ctx) => MainPage(),
},
home: new SplashPage(),
theme: ThemeData.light().copyWith(
primaryColor: _themeColor,
accentColor: _themeColor,
indicatorColor: Colors.white,
),
locale: _locale,
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
CustomLocalizations.delegate
],
supportedLocales: CustomLocalizations.supportedLocales,
);
}
}