veilidchat/lib/theme/models/scale_theme.dart
Christien Rioux 39b0262d0e more log work
2025-02-18 21:43:05 -05:00

89 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'scale_scheme.dart';
class ScaleTileTheme {
ScaleTileTheme(
{required this.textColor,
required this.backgroundColor,
required this.borderColor,
required this.shapeBorder,
required this.largeTextStyle,
required this.smallTextStyle});
final Color textColor;
final Color backgroundColor;
final Color borderColor;
final ShapeBorder shapeBorder;
final TextStyle largeTextStyle;
final TextStyle smallTextStyle;
}
class ScaleTheme extends ThemeExtension<ScaleTheme> {
ScaleTheme({
required this.textTheme,
required this.scheme,
required this.config,
});
final TextTheme textTheme;
final ScaleScheme scheme;
final ScaleConfig config;
@override
ScaleTheme copyWith({
TextTheme? textTheme,
ScaleScheme? scheme,
ScaleConfig? config,
}) =>
ScaleTheme(
textTheme: textTheme ?? this.textTheme,
scheme: scheme ?? this.scheme,
config: config ?? this.config,
);
@override
ScaleTheme lerp(ScaleTheme? other, double t) {
if (other is! ScaleTheme) {
return this;
}
return ScaleTheme(
textTheme: TextTheme.lerp(textTheme, other.textTheme, t),
scheme: scheme.lerp(other.scheme, t),
config: config.lerp(other.config, t));
}
ScaleTileTheme tileTheme(
{bool disabled = false,
bool selected = false,
ScaleKind scaleKind = ScaleKind.primary}) {
final tileColor = scheme.scale(!disabled ? scaleKind : ScaleKind.gray);
final borderColor = selected ? tileColor.hoverBorder : tileColor.border;
final backgroundColor = config.useVisualIndicators && !selected
? tileColor.borderText
: borderColor;
final textColor = config.useVisualIndicators && !selected
? borderColor
: tileColor.borderText;
final largeTextStyle = textTheme.labelMedium!.copyWith(color: textColor);
final smallTextStyle = textTheme.labelSmall!.copyWith(color: textColor);
final shapeBorder = RoundedRectangleBorder(
side: config.useVisualIndicators
? BorderSide(width: 2, color: borderColor, strokeAlign: 0)
: BorderSide.none,
borderRadius: BorderRadius.circular(8 * config.borderRadiusScale));
return ScaleTileTheme(
textColor: textColor,
backgroundColor: backgroundColor,
borderColor: borderColor,
shapeBorder: shapeBorder,
largeTextStyle: largeTextStyle,
smallTextStyle: smallTextStyle,
);
}
}