fluffychat/lib/config/themes.dart

238 lines
8.8 KiB
Dart
Raw Normal View History

2021-09-18 11:08:00 +02:00
import 'package:flutter/cupertino.dart';
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
2021-04-14 10:37:15 +02:00
static const fallbackTextStyle =
2021-10-10 03:42:48 +02:00
TextStyle(fontFamily: 'Roboto', fontFamilyFallback: ['NotoEmoji']);
2021-01-20 11:07:08 +01: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
static ThemeData get light => ThemeData(
visualDensity: VisualDensity.standard,
primaryColorDark: Colors.white,
primaryColorLight: const Color(0xff121212),
brightness: Brightness.light,
primaryColor: AppConfig.chatColor,
colorScheme: ThemeData.light().colorScheme.copyWith(
primary: AppConfig.chatColor,
secondary: AppConfig.chatColor,
secondaryVariant: AppConfig.secondaryColor,
2021-11-15 07:36:07 +01:00
surface: FluffyThemes.lighten(AppConfig.chatColor, 0.535),
),
backgroundColor: Colors.white,
secondaryHeaderColor: Colors.blueGrey.shade50,
scaffoldBackgroundColor: Colors.white,
textTheme: PlatformInfos.isDesktop
? Typography.material2018().black.merge(fallbackTextTheme)
: null,
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(),
},
),
dialogTheme: DialogTheme(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
),
popupMenuTheme: PopupMenuThemeData(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: AppConfig.chatColor,
foregroundColor: Colors.white,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
primary: AppConfig.chatColor,
onPrimary: Colors.white,
elevation: 6,
shadowColor: const Color(0x44000000),
minimumSize: const Size.fromHeight(48),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
padding: const EdgeInsets.all(12),
),
),
cardTheme: CardTheme(
elevation: 6,
shadowColor: const Color(0x44000000),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
clipBehavior: Clip.hardEdge,
),
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
2021-11-15 09:48:21 +01:00
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
borderSide: BorderSide(
color: lighten(AppConfig.chatColor, .51),
2021-11-15 09:48:21 +01:00
width: 1,
),
),
filled: true,
2021-11-15 09:48:21 +01:00
fillColor: Colors.blueGrey.shade50,
),
appBarTheme: const AppBarTheme(
elevation: 6,
shadowColor: Color(0x44000000),
systemOverlayStyle: SystemUiOverlayStyle.dark,
backgroundColor: Colors.white,
titleTextStyle: TextStyle(
color: Colors.black,
fontSize: 20,
),
iconTheme: IconThemeData(color: Colors.black),
),
);
2021-01-15 19:41:55 +01:00
static ThemeData get dark => ThemeData.dark().copyWith(
visualDensity: VisualDensity.standard,
primaryColorDark: const Color(0xff121212),
primaryColorLight: Colors.white,
primaryColor: AppConfig.chatColor,
errorColor: const Color(0xFFCF6679),
backgroundColor: Colors.black,
scaffoldBackgroundColor: Colors.black,
colorScheme: ThemeData.dark().colorScheme.copyWith(
2021-11-14 20:44:38 +01:00
primary: FluffyThemes.lighten(AppConfig.chatColor, 0.33),
secondary: FluffyThemes.lighten(AppConfig.chatColor, 0.33),
secondaryVariant: AppConfig.secondaryColor,
2021-11-22 19:16:43 +01:00
surface: FluffyThemes.darken(AppConfig.chatColor, 0.35),
),
secondaryHeaderColor: Colors.blueGrey.shade900,
textTheme: PlatformInfos.isDesktop
? Typography.material2018().white.merge(fallbackTextTheme)
: null,
dialogTheme: DialogTheme(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
),
popupMenuTheme: PopupMenuThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
),
cardTheme: CardTheme(
elevation: 7,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
clipBehavior: Clip.hardEdge,
),
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.fuchsia: ZoomPageTransitionsBuilder(),
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.linux: CupertinoPageTransitionsBuilder(),
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.windows: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: AppConfig.chatColor,
foregroundColor: Colors.white,
),
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius)),
filled: true,
2021-11-15 09:48:21 +01:00
fillColor: Colors.blueGrey.shade900,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
borderSide: BorderSide(
color: FluffyThemes.darken(AppConfig.chatColor, .31),
),
),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
primary: AppConfig.chatColor,
onPrimary: Colors.white,
minimumSize: const Size.fromHeight(48),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
padding: const EdgeInsets.all(12),
),
),
snackBarTheme:
const SnackBarThemeData(behavior: SnackBarBehavior.floating),
appBarTheme: const AppBarTheme(
elevation: 6,
systemOverlayStyle: SystemUiOverlayStyle.light,
backgroundColor: Color(0xff1D1D1D),
titleTextStyle: TextStyle(
color: Colors.white,
fontSize: 20,
),
iconTheme: IconThemeData(color: Colors.white),
),
cupertinoOverrideTheme: const CupertinoThemeData(
textTheme: CupertinoTextThemeData(),
),
);
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
}