theme work

This commit is contained in:
Christien Rioux 2023-08-17 18:10:24 -04:00
parent e76e3cf0ba
commit 411705283d
17 changed files with 373 additions and 87 deletions

View file

@ -4,11 +4,14 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../entities/preferences.dart';
import 'radix_generator.dart';
part 'theme_service.g.dart';
class ScaleColor {
ScaleColor({
required this.appBackground,
@ -191,17 +194,29 @@ class ThemeService {
Brightness.dark;
ThemeData get initial {
final themePreferencesJson = prefs.getString('themePreferences');
final themePreferences = themePreferencesJson != null
? ThemePreferences.fromJson(themePreferencesJson)
: const ThemePreferences(
colorPreference: ColorPreference.vapor,
brightnessPreference: BrightnessPreference.system,
displayScale: 1,
);
final themePreferences = load();
return get(themePreferences);
}
ThemePreferences load() {
final themePreferencesJson = prefs.getString('themePreferences');
ThemePreferences? themePreferences;
if (themePreferencesJson != null) {
try {
themePreferences = ThemePreferences.fromJson(themePreferencesJson);
// ignore: avoid_catches_without_on_clauses
} catch (_) {
// ignore
}
}
return themePreferences ??
const ThemePreferences(
colorPreference: ColorPreference.vapor,
brightnessPreference: BrightnessPreference.system,
displayScale: 1,
);
}
Future<void> save(ThemePreferences themePreferences) async {
await prefs.setString(
'themePreferences', jsonEncode(themePreferences.toJson()));
@ -256,3 +271,6 @@ class ThemeService {
return themeData;
}
}
@riverpod
Future<ThemeService> themeService() => ThemeService.instance;