mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-04-25 01:29:17 -04:00
308 lines
12 KiB
Dart
308 lines
12 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'radix_generator.dart';
|
|
import 'scale_theme/scale_theme.dart';
|
|
|
|
ScaleColor _contrastScaleColor(
|
|
{required Brightness brightness,
|
|
required Color frontColor,
|
|
required Color backColor}) {
|
|
final back = brightness == Brightness.light ? backColor : frontColor;
|
|
final front = brightness == Brightness.light ? frontColor : backColor;
|
|
|
|
return ScaleColor(
|
|
appBackground: back,
|
|
subtleBackground: back,
|
|
elementBackground: back,
|
|
hoverElementBackground: back,
|
|
activeElementBackground: back,
|
|
subtleBorder: front,
|
|
border: front,
|
|
hoverBorder: front,
|
|
primary: back,
|
|
hoverPrimary: back,
|
|
subtleText: front,
|
|
appText: front,
|
|
primaryText: front,
|
|
borderText: back,
|
|
dialogBorder: front,
|
|
dialogBorderText: back,
|
|
calloutBackground: front,
|
|
calloutText: back,
|
|
);
|
|
}
|
|
|
|
const kMonoSpaceFontDisplay = 'Source Code Pro';
|
|
const kMonoSpaceFontText = 'Source Code Pro';
|
|
|
|
TextTheme makeMonoSpaceTextTheme(Brightness brightness) =>
|
|
(brightness == Brightness.light)
|
|
? const TextTheme(
|
|
displayLarge: TextStyle(
|
|
debugLabel: 'blackMonoSpace displayLarge',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.black54,
|
|
decoration: TextDecoration.none),
|
|
displayMedium: TextStyle(
|
|
debugLabel: 'blackMonoSpace displayMedium',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.black54,
|
|
decoration: TextDecoration.none),
|
|
displaySmall: TextStyle(
|
|
debugLabel: 'blackMonoSpace displaySmall',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.black54,
|
|
decoration: TextDecoration.none),
|
|
headlineLarge: TextStyle(
|
|
debugLabel: 'blackMonoSpace headlineLarge',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.black54,
|
|
decoration: TextDecoration.none),
|
|
headlineMedium: TextStyle(
|
|
debugLabel: 'blackMonoSpace headlineMedium',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.black54,
|
|
decoration: TextDecoration.none),
|
|
headlineSmall: TextStyle(
|
|
debugLabel: 'blackMonoSpace headlineSmall',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.black87,
|
|
decoration: TextDecoration.none),
|
|
titleLarge: TextStyle(
|
|
debugLabel: 'blackMonoSpace titleLarge',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.black87,
|
|
decoration: TextDecoration.none),
|
|
titleMedium: TextStyle(
|
|
debugLabel: 'blackMonoSpace titleMedium',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.black87,
|
|
decoration: TextDecoration.none),
|
|
titleSmall: TextStyle(
|
|
debugLabel: 'blackMonoSpace titleSmall',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.black,
|
|
decoration: TextDecoration.none),
|
|
bodyLarge: TextStyle(
|
|
debugLabel: 'blackMonoSpace bodyLarge',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.black87,
|
|
decoration: TextDecoration.none),
|
|
bodyMedium: TextStyle(
|
|
debugLabel: 'blackMonoSpace bodyMedium',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.black87,
|
|
decoration: TextDecoration.none),
|
|
bodySmall: TextStyle(
|
|
debugLabel: 'blackMonoSpace bodySmall',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.black54,
|
|
decoration: TextDecoration.none),
|
|
labelLarge: TextStyle(
|
|
debugLabel: 'blackMonoSpace labelLarge',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.black87,
|
|
decoration: TextDecoration.none),
|
|
labelMedium: TextStyle(
|
|
debugLabel: 'blackMonoSpace labelMedium',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.black,
|
|
decoration: TextDecoration.none),
|
|
labelSmall: TextStyle(
|
|
debugLabel: 'blackMonoSpace labelSmall',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.black,
|
|
decoration: TextDecoration.none),
|
|
)
|
|
: const TextTheme(
|
|
displayLarge: TextStyle(
|
|
debugLabel: 'whiteMonoSpace displayLarge',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.white70,
|
|
decoration: TextDecoration.none),
|
|
displayMedium: TextStyle(
|
|
debugLabel: 'whiteMonoSpace displayMedium',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.white70,
|
|
decoration: TextDecoration.none),
|
|
displaySmall: TextStyle(
|
|
debugLabel: 'whiteMonoSpace displaySmall',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.white70,
|
|
decoration: TextDecoration.none),
|
|
headlineLarge: TextStyle(
|
|
debugLabel: 'whiteMonoSpace headlineLarge',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.white70,
|
|
decoration: TextDecoration.none),
|
|
headlineMedium: TextStyle(
|
|
debugLabel: 'whiteMonoSpace headlineMedium',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.white70,
|
|
decoration: TextDecoration.none),
|
|
headlineSmall: TextStyle(
|
|
debugLabel: 'whiteMonoSpace headlineSmall',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
titleLarge: TextStyle(
|
|
debugLabel: 'whiteMonoSpace titleLarge',
|
|
fontFamily: kMonoSpaceFontDisplay,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
titleMedium: TextStyle(
|
|
debugLabel: 'whiteMonoSpace titleMedium',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
titleSmall: TextStyle(
|
|
debugLabel: 'whiteMonoSpace titleSmall',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
bodyLarge: TextStyle(
|
|
debugLabel: 'whiteMonoSpace bodyLarge',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
bodyMedium: TextStyle(
|
|
debugLabel: 'whiteMonoSpace bodyMedium',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
bodySmall: TextStyle(
|
|
debugLabel: 'whiteMonoSpace bodySmall',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.white70,
|
|
decoration: TextDecoration.none),
|
|
labelLarge: TextStyle(
|
|
debugLabel: 'whiteMonoSpace labelLarge',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
labelMedium: TextStyle(
|
|
debugLabel: 'whiteMonoSpace labelMedium',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
labelSmall: TextStyle(
|
|
debugLabel: 'whiteMonoSpace labelSmall',
|
|
fontFamily: kMonoSpaceFontText,
|
|
color: Colors.white,
|
|
decoration: TextDecoration.none),
|
|
);
|
|
|
|
ScaleScheme _contrastScaleScheme(
|
|
{required Brightness brightness,
|
|
required Color primaryFront,
|
|
required Color primaryBack,
|
|
required Color secondaryFront,
|
|
required Color secondaryBack,
|
|
required Color tertiaryFront,
|
|
required Color tertiaryBack,
|
|
required Color grayFront,
|
|
required Color grayBack,
|
|
required Color errorFront,
|
|
required Color errorBack}) =>
|
|
ScaleScheme(
|
|
primaryScale: _contrastScaleColor(
|
|
brightness: brightness,
|
|
frontColor: primaryFront,
|
|
backColor: primaryBack),
|
|
primaryAlphaScale: _contrastScaleColor(
|
|
brightness: brightness,
|
|
frontColor: primaryFront,
|
|
backColor: primaryBack),
|
|
secondaryScale: _contrastScaleColor(
|
|
brightness: brightness,
|
|
frontColor: secondaryFront,
|
|
backColor: secondaryBack),
|
|
tertiaryScale: _contrastScaleColor(
|
|
brightness: brightness,
|
|
frontColor: tertiaryFront,
|
|
backColor: tertiaryBack),
|
|
grayScale: _contrastScaleColor(
|
|
brightness: brightness, frontColor: grayFront, backColor: grayBack),
|
|
errorScale: _contrastScaleColor(
|
|
brightness: brightness,
|
|
frontColor: errorFront,
|
|
backColor: errorBack));
|
|
|
|
ThemeData contrastGenerator({
|
|
required Brightness brightness,
|
|
required ScaleConfig scaleConfig,
|
|
required Color primaryFront,
|
|
required Color primaryBack,
|
|
required Color secondaryFront,
|
|
required Color secondaryBack,
|
|
required Color tertiaryFront,
|
|
required Color tertiaryBack,
|
|
required Color grayFront,
|
|
required Color grayBack,
|
|
required Color errorFront,
|
|
required Color errorBack,
|
|
TextTheme? customTextTheme,
|
|
}) {
|
|
final textTheme = customTextTheme ?? makeRadixTextTheme(brightness);
|
|
final scheme = _contrastScaleScheme(
|
|
brightness: brightness,
|
|
primaryFront: primaryFront,
|
|
primaryBack: primaryBack,
|
|
secondaryFront: secondaryFront,
|
|
secondaryBack: secondaryBack,
|
|
tertiaryFront: tertiaryFront,
|
|
tertiaryBack: tertiaryBack,
|
|
grayFront: grayFront,
|
|
grayBack: grayBack,
|
|
errorFront: errorFront,
|
|
errorBack: errorBack,
|
|
);
|
|
|
|
final scaleTheme =
|
|
ScaleTheme(textTheme: textTheme, scheme: scheme, config: scaleConfig);
|
|
|
|
final baseThemeData = scaleTheme.toThemeData(brightness);
|
|
|
|
final elevatedButtonTheme = ElevatedButtonThemeData(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: scheme.primaryScale.elementBackground,
|
|
foregroundColor: scheme.primaryScale.appText,
|
|
disabledBackgroundColor:
|
|
scheme.grayScale.elementBackground.withAlpha(0x7F),
|
|
disabledForegroundColor: scheme.grayScale.appText.withAlpha(0x7F),
|
|
shape: RoundedRectangleBorder(
|
|
side: BorderSide(color: scheme.primaryScale.border),
|
|
borderRadius:
|
|
BorderRadius.circular(8 * scaleConfig.borderRadiusScale)))
|
|
.copyWith(side: WidgetStateProperty.resolveWith((states) {
|
|
if (states.contains(WidgetState.disabled)) {
|
|
return BorderSide(color: scheme.grayScale.border.withAlpha(0x7F));
|
|
} else if (states.contains(WidgetState.pressed)) {
|
|
return BorderSide(
|
|
color: scheme.primaryScale.border,
|
|
strokeAlign: BorderSide.strokeAlignOutside);
|
|
} else if (states.contains(WidgetState.hovered)) {
|
|
return BorderSide(color: scheme.primaryScale.hoverBorder);
|
|
} else if (states.contains(WidgetState.focused)) {
|
|
return BorderSide(color: scheme.primaryScale.hoverBorder, width: 2);
|
|
}
|
|
return BorderSide(color: scheme.primaryScale.border);
|
|
})));
|
|
|
|
final themeData = baseThemeData.copyWith(
|
|
// chipTheme: baseThemeData.chipTheme.copyWith(
|
|
// backgroundColor: scaleScheme.primaryScale.elementBackground,
|
|
// selectedColor: scaleScheme.primaryScale.activeElementBackground,
|
|
// surfaceTintColor: scaleScheme.primaryScale.hoverElementBackground,
|
|
// checkmarkColor: scaleScheme.primaryScale.border,
|
|
// side: BorderSide(color: scaleScheme.primaryScale.border)),
|
|
elevatedButtonTheme: elevatedButtonTheme,
|
|
textSelectionTheme: TextSelectionThemeData(
|
|
cursorColor: scheme.primaryScale.appText,
|
|
selectionColor: scheme.primaryScale.appText.withAlpha(0x7F),
|
|
selectionHandleColor: scheme.primaryScale.appText),
|
|
extensions: <ThemeExtension<dynamic>>[scheme, scaleConfig, scaleTheme]);
|
|
|
|
return themeData;
|
|
}
|