making sure stores are initialiazed before rendering

This commit is contained in:
shilangyu 2020-08-31 17:52:16 +02:00
parent 9133ef94cd
commit 8c52ec1109
2 changed files with 11 additions and 6 deletions

View File

@ -8,12 +8,17 @@ import 'package:provider/provider.dart';
import 'pages/profile_tab.dart';
import 'stores/config_store.dart';
void main() {
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
var configStore = ConfigStore();
await configStore.load();
runApp(
MultiProvider(
providers: [
Provider<ConfigStore>(
create: (_) => ConfigStore()..load(),
create: (_) => configStore,
dispose: (_, store) => store.dispose(),
),
],
@ -34,7 +39,7 @@ class MyApp extends StatelessWidget {
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: UserProfileTab(User.fromJson(jsonDecode(
'''{"id":13917,"name":"shilangyu","preferred_username":null,"password_encrypted":"","email":"xmarcinmarcin@gmail.com","avatar":null,"admin":false,"banned":false,"published":"2020-08-23T07:13:23.229279","updated":"2020-08-29T21:11:11.508707","show_nsfw":true,"theme":"minty","default_sort_type":0,"default_listing_type":1,"lang":"browser","show_avatars":true,"send_notifications_to_email":false,"matrix_user_id":null,"actor_id":"https://dev.lemmy.ml/u/shilangyu","bio":null,"local":true,"private_key":null,"public_key":null,"last_refreshed_at":"2020-08-23T07:13:23.229279","banner":null}'''))),
'''{"id":13917,"name":"shilangyu","preferred_username":null,"password_encrypted":"","email":"xmarcinmarcin@gmail.com","avatar":null,"admin":false,"banned":false,"published":"2020-08-23T07:13:23.229279","updated":"2020-08-31T14:24:42.495740","show_nsfw":true,"theme":"minty","default_sort_type":0,"default_listing_type":1,"lang":"browser","show_avatars":true,"send_notifications_to_email":false,"matrix_user_id":null,"actor_id":"https://dev.lemmy.ml/u/shilangyu","bio":null,"local":true,"private_key":null,"public_key":null,"last_refreshed_at":"2020-08-23T07:13:23.229279","banner":"https://dev.lemmy.ml/pictrs/image/Cdx3TfNb8g.jpg"}'''))),
),
);
}

View File

@ -24,7 +24,7 @@ abstract class _ConfigStore with Store {
void load() async {
var prefs = await SharedPreferences.getInstance();
// set saved settings or create defaults
theme = _themeModeFromString(prefs.getString('theme') ?? 'dark');
theme = _themeModeFromString(prefs.getString('theme') ?? 'system');
}
void save() async {
@ -34,10 +34,10 @@ abstract class _ConfigStore with Store {
}
@observable
ThemeMode theme = ThemeMode.dark;
ThemeMode theme;
@observable
MaterialColor accentColor = Colors.green;
MaterialColor accentColor;
}
ThemeMode _themeModeFromString(String theme) =>