fluffychat/lib/config/themes.dart

169 lines
5.5 KiB
Dart
Raw Normal View History

2021-01-15 18:41:55 +00:00
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
2021-01-20 10:07:08 +00:00
import 'package:fluffychat/utils/platform_infos.dart';
2021-01-15 18:41:55 +00:00
2021-01-24 15:38:25 +00:00
import '../app_config.dart';
2021-01-15 18:41:55 +00:00
abstract class FluffyThemes {
2021-01-16 11:46:38 +00:00
static const double columnWidth = 360.0;
2021-01-20 10:07:08 +00:00
static const fallback_text_style =
TextStyle(fontFamily: 'NotoSans', fontFamilyFallback: ['NotoEmoji']);
2021-01-20 10:07:08 +00:00
static var fallback_text_theme = PlatformInfos.isDesktop
? TextTheme(
bodyText1: fallback_text_style,
bodyText2: fallback_text_style,
button: fallback_text_style,
caption: fallback_text_style,
overline: fallback_text_style,
headline1: fallback_text_style,
headline2: fallback_text_style,
headline3: fallback_text_style,
headline4: fallback_text_style,
headline5: fallback_text_style,
headline6: fallback_text_style,
subtitle1: fallback_text_style,
subtitle2: fallback_text_style)
: TextTheme();
2021-01-15 18:41:55 +00:00
static ThemeData light = ThemeData(
primaryColorDark: Colors.white,
primaryColorLight: Color(0xff121212),
brightness: Brightness.light,
2021-01-24 15:38:25 +00:00
primaryColor: AppConfig.primaryColor,
2021-01-24 16:37:55 +00:00
accentColor: AppConfig.primaryColor,
2021-01-15 18:41:55 +00:00
backgroundColor: Colors.white,
2021-02-07 08:31:24 +00:00
secondaryHeaderColor: lighten(AppConfig.primaryColor, .51),
2021-01-15 18:41:55 +00:00
scaffoldBackgroundColor: Colors.white,
2021-01-20 10:07:08 +00:00
textTheme: Typography.material2018().black.merge(fallback_text_theme),
2021-01-15 18:41:55 +00:00
snackBarTheme: SnackBarThemeData(
behavior: kIsWeb ? SnackBarBehavior.floating : SnackBarBehavior.fixed,
),
dialogTheme: DialogTheme(
shape: RoundedRectangleBorder(
2021-02-07 08:12:34 +00:00
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
2021-01-15 18:41:55 +00:00
),
),
popupMenuTheme: PopupMenuThemeData(
shape: RoundedRectangleBorder(
2021-02-07 08:12:34 +00:00
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
2021-01-15 18:41:55 +00:00
),
),
2021-01-24 15:38:25 +00:00
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: AppConfig.primaryColor,
foregroundColor: Colors.white,
),
2021-01-24 16:26:59 +00:00
inputDecorationTheme: InputDecorationTheme(
2021-02-07 08:12:34 +00:00
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius)),
2021-02-03 14:05:05 +00:00
enabledBorder: OutlineInputBorder(
2021-02-07 08:12:34 +00:00
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
2021-02-03 14:05:05 +00:00
borderSide: BorderSide(
2021-02-07 08:31:24 +00:00
color: lighten(AppConfig.primaryColor, .51),
2021-02-03 14:05:05 +00:00
),
),
2021-01-24 16:26:59 +00:00
filled: true,
2021-02-07 08:31:24 +00:00
fillColor: lighten(AppConfig.primaryColor, .51),
2021-01-24 16:26:59 +00:00
),
2021-01-15 18:41:55 +00:00
appBarTheme: AppBarTheme(
2021-02-07 09:36:42 +00:00
elevation: 1,
2021-01-15 18:41:55 +00:00
brightness: Brightness.light,
color: Colors.white,
textTheme: TextTheme(
headline6: TextStyle(
color: Colors.black,
fontSize: 20,
),
),
iconTheme: IconThemeData(color: Colors.black),
),
);
2021-01-24 15:45:05 +00:00
static ThemeData dark = ThemeData.dark().copyWith(
2021-01-15 18:41:55 +00:00
primaryColorDark: Color(0xff121212),
primaryColorLight: Colors.white,
2021-01-24 16:37:55 +00:00
primaryColor: AppConfig.primaryColor,
2021-01-15 18:41:55 +00:00
errorColor: Color(0xFFCF6679),
backgroundColor: Colors.black,
scaffoldBackgroundColor: Colors.black,
2021-01-24 16:37:55 +00:00
accentColor: AppConfig.primaryColorLight,
2021-02-07 08:31:24 +00:00
secondaryHeaderColor: FluffyThemes.darken(AppConfig.primaryColorLight, .71),
2021-01-20 10:07:08 +00:00
textTheme: Typography.material2018().white.merge(fallback_text_theme),
2021-01-24 15:45:05 +00:00
dialogTheme: DialogTheme(
shape: RoundedRectangleBorder(
2021-02-07 08:12:34 +00:00
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
2021-01-24 15:45:05 +00:00
),
),
popupMenuTheme: PopupMenuThemeData(
shape: RoundedRectangleBorder(
2021-02-07 08:12:34 +00:00
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
2021-01-24 15:45:05 +00:00
),
),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: AppConfig.primaryColor,
foregroundColor: Colors.white,
),
2021-01-24 16:37:55 +00:00
inputDecorationTheme: InputDecorationTheme(
2021-02-07 08:12:34 +00:00
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius)),
2021-01-24 16:37:55 +00:00
filled: true,
2021-02-07 08:31:24 +00:00
fillColor: FluffyThemes.darken(AppConfig.primaryColorLight, .71),
2021-02-03 14:05:05 +00:00
enabledBorder: OutlineInputBorder(
2021-02-07 08:12:34 +00:00
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
2021-02-03 14:05:05 +00:00
borderSide: BorderSide(
2021-02-07 08:31:24 +00:00
color: FluffyThemes.darken(AppConfig.primaryColor, .31),
2021-02-03 14:05:05 +00:00
),
),
2021-01-24 16:37:55 +00:00
),
2021-01-15 18:41:55 +00:00
appBarTheme: AppBarTheme(
2021-02-07 09:36:42 +00:00
elevation: 1,
2021-01-15 18:41:55 +00:00
brightness: Brightness.dark,
color: Color(0xff1D1D1D),
textTheme: TextTheme(
headline6: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
iconTheme: IconThemeData(color: Colors.white),
),
);
static Color chatListItemColor(
BuildContext context, bool activeChat, bool selected) =>
selected
? Theme.of(context).primaryColor.withAlpha(100)
: Theme.of(context).brightness == Brightness.light
? activeChat
? Color(0xFFE8E8E8)
: Colors.white
: activeChat
? Color(0xff121212)
: Colors.black;
static Color blackWhiteColor(BuildContext context) =>
Theme.of(context).brightness == Brightness.light
? Colors.white
: Colors.black;
2021-02-07 08:31:24 +00:00
static Color darken(Color color, [double amount = .1]) {
assert(amount >= 0 && amount <= 1);
final hsl = HSLColor.fromColor(color);
final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0));
return hslDark.toColor();
}
static Color lighten(Color color, [double amount = .1]) {
assert(amount >= 0 && amount <= 1);
final hsl = HSLColor.fromColor(color);
final hslLight =
hsl.withLightness((hsl.lightness + amount).clamp(0.0, 1.0));
return hslLight.toColor();
}
2021-01-15 18:41:55 +00:00
}