veilidchat/lib/theme/models/scale_theme/scale_toast_theme.dart
Christien Rioux 77c68aa45f ui cleanup
2025-03-17 00:51:16 -04:00

71 lines
2.3 KiB
Dart

import 'package:flutter/material.dart';
import 'scale_theme.dart';
enum ScaleToastKind {
info,
error,
}
class ScaleToastTheme {
ScaleToastTheme(
{required this.primaryColor,
required this.backgroundColor,
required this.foregroundColor,
required this.borderSide,
required this.borderRadius,
required this.padding,
required this.icon,
required this.titleTextStyle,
required this.descriptionTextStyle});
final Color primaryColor;
final Color backgroundColor;
final Color foregroundColor;
final BorderSide? borderSide;
final BorderRadiusGeometry borderRadius;
final EdgeInsetsGeometry padding;
final Icon icon;
final TextStyle titleTextStyle;
final TextStyle descriptionTextStyle;
}
extension ScaleToastThemeExt on ScaleTheme {
ScaleToastTheme toastTheme(ScaleToastKind kind) {
final toastScaleColor = scheme.scale(ScaleKind.tertiary);
final primaryColor = toastScaleColor.calloutText;
final borderColor = toastScaleColor.border;
final backgroundColor = config.useVisualIndicators
? toastScaleColor.calloutText
: toastScaleColor.calloutBackground;
final textColor = config.useVisualIndicators
? toastScaleColor.calloutBackground
: toastScaleColor.calloutText;
final titleColor = config.useVisualIndicators
? toastScaleColor.calloutBackground
: toastScaleColor.calloutText;
Icon icon;
switch (kind) {
case ScaleToastKind.info:
icon = Icon(Icons.info, size: 32, color: primaryColor);
case ScaleToastKind.error:
icon = Icon(Icons.dangerous, size: 32, color: primaryColor);
}
return ScaleToastTheme(
primaryColor: primaryColor,
backgroundColor: backgroundColor,
foregroundColor: textColor,
borderSide: (config.useVisualIndicators || config.preferBorders)
? BorderSide(color: borderColor, width: 2)
: const BorderSide(color: Colors.transparent, width: 0),
borderRadius: BorderRadius.circular(12 * config.borderRadiusScale),
padding: const EdgeInsets.all(8),
icon: icon,
titleTextStyle: textTheme.labelMedium!.copyWith(color: titleColor),
descriptionTextStyle:
textTheme.labelMedium!.copyWith(color: textColor));
}
}