2024-11-08 16:09:46 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-11-10 13:48:42 +00:00
|
|
|
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});
|
|
|
|
}
|
|
|
|
|
2024-11-10 13:48:42 +00:00
|
|
|
Future<ThemeSet> createAppThemeSet({bool? useMaterial3}) async {
|
2024-11-08 16:09:46 +00:00
|
|
|
return ThemeSet(
|
2024-11-10 13:48:42 +00:00
|
|
|
light: await createAppTheme(Brightness.light, useMaterial3: useMaterial3),
|
|
|
|
dark: await createAppTheme(Brightness.dark, useMaterial3: useMaterial3),
|
2024-11-08 16:09:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-11-10 13:48:42 +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-12-09 14:57:20 +00:00
|
|
|
final hasBackground = prefs.getBool('has_background_image') ?? false;
|
|
|
|
|
2024-11-08 16:09:46 +00:00
|
|
|
return ThemeData(
|
2024-12-09 14:57:20 +00:00
|
|
|
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,
|
|
|
|
),
|
2024-11-24 12:23:06 +00:00
|
|
|
appBarTheme: AppBarTheme(
|
|
|
|
centerTitle: true,
|
2024-12-09 14:57:20 +00:00
|
|
|
backgroundColor: hasBackground ? colorScheme.primary.withOpacity(0.75) : colorScheme.primary,
|
|
|
|
foregroundColor: colorScheme.onPrimary,
|
2024-11-24 12:23:06 +00:00
|
|
|
),
|
2024-11-10 13:48:42 +00:00
|
|
|
scaffoldBackgroundColor: Colors.transparent,
|
2024-11-08 16:09:46 +00:00
|
|
|
);
|
|
|
|
}
|