First iteration of persistent settings (#45)

This commit is contained in:
tommyxchow 2021-11-23 03:26:57 -05:00
parent 9875b6ed59
commit 7dc5b114fb
2 changed files with 12 additions and 20 deletions

View file

@ -185,7 +185,7 @@ enum Command {
none,
}
// https://stackoverflow.com/questions/50081213/how-do-i-use-hexadecimal-color-strings-in-flutter
/// https://stackoverflow.com/questions/50081213/how-do-i-use-hexadecimal-color-strings-in-flutter
extension HexColor on Color {
/// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
static Color fromHex(String hexString) {
@ -194,11 +194,4 @@ extension HexColor on Color {
buffer.write(hexString.replaceFirst('#', ''));
return Color(int.parse(buffer.toString(), radix: 16));
}
/// Prefixes a hash sign if [leadingHashSign] is set to `true` (default is `true`).
String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
'${alpha.toRadixString(16).padLeft(2, '0')}'
'${red.toRadixString(16).padLeft(2, '0')}'
'${green.toRadixString(16).padLeft(2, '0')}'
'${blue.toRadixString(16).padLeft(2, '0')}';
}

View file

@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -6,21 +7,19 @@ part 'settings_store.g.dart';
class SettingsStore = _SettingsStoreBase with _$SettingsStore;
abstract class _SettingsStoreBase with Store {
late final SharedPreferences prefs;
late ReactionDisposer disposeSetter;
Future<void> init() async {
// debugPrint('Created settings provider!');
// prefs = await SharedPreferences.getInstance();
// Retrieve the instance that will allow us to store and persist settings.
final prefs = await SharedPreferences.getInstance();
// // Initialize settings from stored preferences if any.
// videoEnabled = prefs.getBool('video_enabled') ?? videoEnabled;
// Initialize settings from stored preferences if any.
videoEnabled = prefs.getBool('video_enabled') ?? videoEnabled;
// // Set up autorun to store setting anytime they're changed.
// disposeSetter = autorun((_) {
// debugPrint('video changed');
// prefs.setBool('video_enabled', videoEnabled);
// });
// Set up autorun to store setting anytime they're changed.
// The ReactionDisposer will not be needed since settings will always exist.
autorun((_) {
debugPrint('video changed');
prefs.setBool('video_enabled', videoEnabled);
});
}
@observable