mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 14:29:22 +00:00
Create ApplicationPreferences object
This commit is contained in:
parent
57e504540a
commit
c747d3c1ba
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:comunic/models/application_preferences.dart';
|
||||||
import 'package:comunic/models/login_tokens.dart';
|
import 'package:comunic/models/login_tokens.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
@ -70,6 +71,12 @@ class PreferencesHelper {
|
|||||||
final v = _sharedPreferences.getBool(_PreferenceKeysName[key]);
|
final v = _sharedPreferences.getBool(_PreferenceKeysName[key]);
|
||||||
return v == null ? alternative : v;
|
return v == null ? alternative : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get all settings as an [ApplicationPreferences] object
|
||||||
|
ApplicationPreferences get preferences => ApplicationPreferences(
|
||||||
|
enableDarkMode:
|
||||||
|
getBool(PreferencesKeyList.ENABLE_DARK_THEME, alternative: null),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferencesHelper preferences() {
|
PreferencesHelper preferences() {
|
||||||
|
@ -24,21 +24,20 @@ void subMain() async {
|
|||||||
final signedIn = await AccountHelper().signedIn();
|
final signedIn = await AccountHelper().signedIn();
|
||||||
|
|
||||||
runApp(ComunicApplication(
|
runApp(ComunicApplication(
|
||||||
darkMode: (await PreferencesHelper.getInstance())
|
preferences: await PreferencesHelper.getInstance(),
|
||||||
.getBool(PreferencesKeyList.ENABLE_DARK_THEME),
|
|
||||||
signedIn: signedIn,
|
signedIn: signedIn,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComunicApplication extends StatelessWidget {
|
class ComunicApplication extends StatelessWidget {
|
||||||
final bool darkMode;
|
final PreferencesHelper preferences;
|
||||||
final bool signedIn;
|
final bool signedIn;
|
||||||
|
|
||||||
const ComunicApplication({
|
const ComunicApplication({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.darkMode,
|
@required this.preferences,
|
||||||
@required this.signedIn,
|
@required this.signedIn,
|
||||||
}) : assert(darkMode != null),
|
}) : assert(preferences != null),
|
||||||
assert(signedIn != null),
|
assert(signedIn != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ class ComunicApplication extends StatelessWidget {
|
|||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: signedIn ? InitializeWidget() : LoginRoute(),
|
home: signedIn ? InitializeWidget() : LoginRoute(),
|
||||||
theme: darkMode ? ThemeData.dark() : ThemeData.light(),
|
theme: preferences.preferences.enableDarkMode ? ThemeData.dark() : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
lib/models/application_preferences.dart
Normal file
13
lib/models/application_preferences.dart
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
|
/// Application settings
|
||||||
|
///
|
||||||
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
|
class ApplicationPreferences {
|
||||||
|
final bool enableDarkMode;
|
||||||
|
|
||||||
|
const ApplicationPreferences({
|
||||||
|
@required this.enableDarkMode,
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user