Surface/lib/theme.dart

45 lines
1.1 KiB
Dart
Raw Normal View History

2024-11-08 16:09:46 +00:00
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
const kMaterialYouToggleStoreKey = 'app_theme_material_you';
2024-11-08 16:09:46 +00:00
class ThemeSet {
ThemeData light;
ThemeData dark;
ThemeSet({required this.light, required this.dark});
}
Future<ThemeSet> createAppThemeSet({bool? useMaterial3}) async {
2024-11-08 16:09:46 +00:00
return ThemeSet(
light: await createAppTheme(Brightness.light, useMaterial3: useMaterial3),
dark: await createAppTheme(Brightness.dark, useMaterial3: useMaterial3),
2024-11-08 16:09:46 +00:00
);
}
Future<ThemeData> createAppTheme(
Brightness brightness, {
bool? useMaterial3,
}) async {
final prefs = await SharedPreferences.getInstance();
2024-11-10 14:56:09 +00:00
final colorScheme = ColorScheme.fromSeed(
seedColor: Colors.indigo,
brightness: brightness,
);
2024-11-08 16:09:46 +00:00
return ThemeData(
useMaterial3:
useMaterial3 ?? (prefs.getBool(kMaterialYouToggleStoreKey) ?? false),
2024-11-10 14:56:09 +00:00
colorScheme: colorScheme,
2024-11-10 04:41:56 +00:00
brightness: brightness,
2024-11-10 14:56:09 +00:00
iconTheme: IconThemeData(
fill: 0,
weight: 400,
opticalSize: 20,
color: colorScheme.onSurface,
),
scaffoldBackgroundColor: Colors.transparent,
2024-11-08 16:09:46 +00:00
);
}