fluffychat/lib/config/themes.dart

119 lines
4.2 KiB
Dart
Raw Normal View History

2021-01-15 19:41:55 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2021-01-15 19:41:55 +01:00
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/utils/platform_infos.dart';
2021-04-09 16:29:48 +02:00
import 'app_config.dart';
2021-01-24 16:38:25 +01:00
2021-01-15 19:41:55 +01:00
abstract class FluffyThemes {
2021-01-16 12:46:38 +01:00
static const double columnWidth = 360.0;
static bool isColumnMode(BuildContext context) =>
MediaQuery.of(context).size.width > columnWidth * 2;
2021-01-20 11:07:08 +01:00
2022-07-07 18:50:13 +02:00
static const fallbackTextStyle = TextStyle(
fontFamily: 'Roboto',
fontFamilyFallback: ['NotoEmoji'],
);
2022-04-15 11:42:59 +02:00
static var fallbackTextTheme = const TextTheme(
bodyText1: fallbackTextStyle,
bodyText2: fallbackTextStyle,
button: fallbackTextStyle,
caption: fallbackTextStyle,
overline: fallbackTextStyle,
headline1: fallbackTextStyle,
headline2: fallbackTextStyle,
headline3: fallbackTextStyle,
headline4: fallbackTextStyle,
headline5: fallbackTextStyle,
headline6: fallbackTextStyle,
subtitle1: fallbackTextStyle,
subtitle2: fallbackTextStyle,
);
2021-01-20 11:07:08 +01:00
2022-05-18 12:13:59 +02:00
static ThemeData light([ColorScheme? colorScheme]) => ThemeData(
visualDensity: VisualDensity.standard,
2022-05-18 08:54:50 +02:00
useMaterial3: true,
brightness: Brightness.light,
2022-05-18 12:13:59 +02:00
colorSchemeSeed: AppConfig.colorSchemeSeed ??
colorScheme?.primary ??
AppConfig.chatColor,
textTheme: PlatformInfos.isDesktop
? Typography.material2018().black.merge(fallbackTextTheme)
: null,
2022-07-07 18:50:13 +02:00
snackBarTheme: const SnackBarThemeData(
behavior: SnackBarBehavior.floating,
),
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.fuchsia: ZoomPageTransitionsBuilder(),
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.linux: CupertinoPageTransitionsBuilder(),
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.windows: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
2022-05-18 08:54:50 +02:00
dividerColor: Colors.blueGrey.shade50,
2022-07-07 18:50:13 +02:00
inputDecorationTheme: const InputDecorationTheme(
border: UnderlineInputBorder(borderSide: BorderSide(width: 1)),
filled: true,
),
appBarTheme: const AppBarTheme(
systemOverlayStyle: SystemUiOverlayStyle.dark,
),
);
2021-01-15 19:41:55 +01:00
2022-05-18 12:13:59 +02:00
static ThemeData dark([ColorScheme? colorScheme]) => ThemeData(
visualDensity: VisualDensity.standard,
2022-05-18 08:54:50 +02:00
useMaterial3: true,
brightness: Brightness.dark,
2022-05-18 12:13:59 +02:00
colorSchemeSeed: AppConfig.colorSchemeSeed ??
colorScheme?.primary ??
AppConfig.chatColor,
textTheme: PlatformInfos.isDesktop
? Typography.material2018().white.merge(fallbackTextTheme)
: null,
2022-05-18 08:54:50 +02:00
snackBarTheme:
const SnackBarThemeData(behavior: SnackBarBehavior.floating),
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.fuchsia: ZoomPageTransitionsBuilder(),
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.linux: CupertinoPageTransitionsBuilder(),
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.windows: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
2022-07-07 18:50:13 +02:00
inputDecorationTheme: const InputDecorationTheme(
border: UnderlineInputBorder(borderSide: BorderSide(width: 1)),
filled: true,
),
2022-07-07 18:50:13 +02:00
dividerColor: Colors.blueGrey.shade900,
);
2021-01-15 19:41:55 +01:00
static Color blackWhiteColor(BuildContext context) =>
Theme.of(context).brightness == Brightness.light
? Colors.white
: Colors.black;
2021-02-07 09:31:24 +01:00
2021-11-14 22:15:37 +01:00
static Color darken(Color color, [double amount = .1]) {
2021-02-07 09:31:24 +01:00
assert(amount >= 0 && amount <= 1);
final hsl = HSLColor.fromColor(color);
2021-11-14 22:15:37 +01:00
final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0));
2021-02-07 09:31:24 +01:00
return hslDark.toColor();
}
2021-11-14 22:15:37 +01:00
static Color lighten(Color color, [double amount = .1]) {
2021-02-07 09:31:24 +01:00
assert(amount >= 0 && amount <= 1);
final hsl = HSLColor.fromColor(color);
2021-11-14 22:15:37 +01:00
final hslLight =
hsl.withLightness((hsl.lightness + amount).clamp(0.0, 1.0));
2021-02-07 09:31:24 +01:00
return hslLight.toColor();
}
2021-01-15 19:41:55 +01:00
}