Surface/lib/theme.dart

51 lines
1.4 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,
);
final hasBackground = prefs.getBool('has_background_image') ?? false;
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,
),
2024-11-24 12:23:06 +00:00
appBarTheme: AppBarTheme(
centerTitle: true,
backgroundColor: hasBackground ? colorScheme.primary.withOpacity(0.75) : colorScheme.primary,
foregroundColor: colorScheme.onPrimary,
2024-11-24 12:23:06 +00:00
),
scaffoldBackgroundColor: Colors.transparent,
2024-11-08 16:09:46 +00:00
);
}