refactor: init before running app
This commit is contained in:
parent
e35d5dfb3a
commit
119a01ce76
|
@ -30,17 +30,6 @@ class _HomeState extends State<Home> {
|
||||||
int active = 0;
|
int active = 0;
|
||||||
// String login;
|
// String login;
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
nextTick(() {
|
|
||||||
// FIXME:
|
|
||||||
Provider.of<ThemeModel>(context).init();
|
|
||||||
Provider.of<AuthModel>(context).init();
|
|
||||||
Provider.of<CodeModel>(context).init();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildNotificationIcon(BuildContext context, bool isActive) {
|
Widget _buildNotificationIcon(BuildContext context, bool isActive) {
|
||||||
final iconData = isActive ? Icons.notifications : Icons.notifications_none;
|
final iconData = isActive ? Icons.notifications : Icons.notifications_none;
|
||||||
int count = Provider.of<NotificationModel>(context).count;
|
int count = Provider.of<NotificationModel>(context).count;
|
||||||
|
@ -201,22 +190,8 @@ class _HomeState extends State<Home> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends StatelessWidget {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MultiProvider(
|
|
||||||
providers: [
|
|
||||||
ChangeNotifierProvider(builder: (context) => NotificationModel()),
|
|
||||||
ChangeNotifierProvider(builder: (context) => ThemeModel()),
|
|
||||||
ChangeNotifierProvider(builder: (context) => AuthModel()),
|
|
||||||
ChangeNotifierProvider(builder: (context) => CodeModel()),
|
|
||||||
],
|
|
||||||
child: Home(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
// Platform messages may fail, so we use a try/catch PlatformException.
|
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
|
@ -236,5 +211,23 @@ void main() async {
|
||||||
// TODO: Later, should check to enable debug log in debug build only
|
// TODO: Later, should check to enable debug log in debug build only
|
||||||
Fimber.plantTree(DebugTree());
|
Fimber.plantTree(DebugTree());
|
||||||
|
|
||||||
runApp(App());
|
final notificationModel = NotificationModel();
|
||||||
|
final themeModel = ThemeModel();
|
||||||
|
final authModel = AuthModel();
|
||||||
|
final codeModel = CodeModel();
|
||||||
|
await Future.wait([
|
||||||
|
themeModel.init(),
|
||||||
|
authModel.init(),
|
||||||
|
codeModel.init(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
runApp(MultiProvider(
|
||||||
|
providers: [
|
||||||
|
ChangeNotifierProvider(builder: (context) => notificationModel),
|
||||||
|
ChangeNotifierProvider(builder: (context) => themeModel),
|
||||||
|
ChangeNotifierProvider(builder: (context) => authModel),
|
||||||
|
ChangeNotifierProvider(builder: (context) => codeModel),
|
||||||
|
],
|
||||||
|
child: Home(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ class AuthModel with ChangeNotifier {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() async {
|
Future<void> init() async {
|
||||||
// Listen scheme
|
// Listen scheme
|
||||||
_sub = getUriLinksStream().listen(_onSchemeDetected, onError: (err) {
|
_sub = getUriLinksStream().listen(_onSchemeDetected, onError: (err) {
|
||||||
Fimber.e('getUriLinksStream failed', ex: err);
|
Fimber.e('getUriLinksStream failed', ex: err);
|
||||||
|
|
|
@ -30,7 +30,7 @@ class CodeModel with ChangeNotifier {
|
||||||
String get fontFamilyUsed =>
|
String get fontFamilyUsed =>
|
||||||
_fontFamily == 'System' ? CommonStyle.monospace : _fontFamily;
|
_fontFamily == 'System' ? CommonStyle.monospace : _fontFamily;
|
||||||
|
|
||||||
init() async {
|
Future<void> init() async {
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var prefs = await SharedPreferences.getInstance();
|
||||||
var vh = prefs.getString(_kTheme);
|
var vh = prefs.getString(_kTheme);
|
||||||
var vs = prefs.getInt(_kFontSize);
|
var vs = prefs.getInt(_kFontSize);
|
||||||
|
|
|
@ -70,7 +70,7 @@ class ThemeModel with ChangeNotifier {
|
||||||
int get theme => _theme;
|
int get theme => _theme;
|
||||||
bool get ready => _theme != null;
|
bool get ready => _theme != null;
|
||||||
|
|
||||||
init() async {
|
Future<void> init() async {
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
int v = prefs.getInt(storageKey);
|
int v = prefs.getInt(storageKey);
|
||||||
|
|
Loading…
Reference in New Issue