Solian/lib/theme.dart

97 lines
2.8 KiB
Dart
Raw Permalink Normal View History

2024-05-18 10:17:16 +00:00
import 'package:flutter/material.dart';
import 'package:solian/models/theme.dart';
2024-06-22 15:59:11 +00:00
import 'package:solian/platform.dart';
2024-05-18 10:17:16 +00:00
abstract class AppTheme {
2024-05-18 10:17:16 +00:00
static bool isLargeScreen(BuildContext context) =>
MediaQuery.of(context).size.width > 640;
2024-06-02 14:45:54 +00:00
static bool isExtraLargeScreen(BuildContext context) =>
MediaQuery.of(context).size.width > 920;
static bool isUltraLargeScreen(BuildContext context) =>
MediaQuery.of(context).size.width > 1200;
2024-06-02 14:45:54 +00:00
2024-06-22 15:59:11 +00:00
static bool isSpecializedMacOS(BuildContext context) =>
PlatformInfo.isMacOS && !AppTheme.isLargeScreen(context);
2024-06-22 15:59:11 +00:00
static double? titleSpacing(BuildContext context) {
if (AppTheme.isSpecializedMacOS(context)) {
2024-06-22 15:59:11 +00:00
return 24;
} else {
return AppTheme.isLargeScreen(context) ? null : 24;
2024-06-22 15:59:11 +00:00
}
}
static double toolbarHeight(BuildContext context) {
if (isLargeScreen(context)) {
return kToolbarHeight;
} else {
return PlatformInfo.isMacOS ? 50 : kToolbarHeight;
}
}
2024-07-30 18:44:49 +00:00
static ThemeData build(Brightness brightness, {Color? seedColor}) {
2024-05-18 10:17:16 +00:00
return ThemeData(
brightness: brightness,
useMaterial3: true,
2024-06-02 14:45:54 +00:00
colorScheme: ColorScheme.fromSeed(
2024-07-30 03:50:26 +00:00
brightness: brightness,
2024-07-30 18:44:49 +00:00
seedColor: seedColor ?? const Color.fromRGBO(154, 98, 91, 1),
2024-07-30 03:50:26 +00:00
),
snackBarTheme: const SnackBarThemeData(
behavior: SnackBarBehavior.floating,
),
2024-10-06 15:06:33 +00:00
scaffoldBackgroundColor: Colors.transparent,
appBarTheme: const AppBarTheme(
backgroundColor: Colors.transparent,
),
2024-07-31 12:45:36 +00:00
fontFamily: 'Comfortaa',
2024-07-31 17:21:27 +00:00
fontFamilyFallback: [
2024-07-31 12:45:36 +00:00
'NotoSansSC',
'NotoSansHK',
'NotoSansJP',
2024-07-31 17:21:27 +00:00
if (PlatformInfo.isWeb) 'NotoSansEmoji',
2024-07-31 12:45:36 +00:00
],
typography: Typography.material2021(
colorScheme: brightness == Brightness.light
? const ColorScheme.light()
: const ColorScheme.dark(),
),
2024-05-18 10:17:16 +00:00
);
}
static ThemeData buildFromData(
Brightness brightness,
SolianThemeData data, {
bool useMaterial3 = true,
}) {
return ThemeData(
brightness: brightness,
useMaterial3: useMaterial3,
colorScheme: ColorScheme.fromSeed(
brightness: brightness,
seedColor: data.seedColor,
),
snackBarTheme: const SnackBarThemeData(
behavior: SnackBarBehavior.floating,
),
scaffoldBackgroundColor: Colors.transparent,
2024-10-06 15:06:33 +00:00
appBarTheme: const AppBarTheme(backgroundColor: Colors.transparent),
fontFamily: data.fontFamily ?? 'Comfortaa',
fontFamilyFallback: data.fontFamilyFallback ??
[
'NotoSansSC',
'NotoSansHK',
'NotoSansJP',
if (PlatformInfo.isWeb) 'NotoSansEmoji',
],
typography: Typography.material2021(
colorScheme: brightness == Brightness.light
? const ColorScheme.light()
: const ColorScheme.dark(),
),
);
}
2024-06-02 14:45:54 +00:00
}