tasq/lib/theme/app_surfaces.dart

92 lines
2.9 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
/// M3 Expressive surface tokens.
///
/// Cards now use **tonal elevation** (color tints) instead of drop-shadows.
/// Large containers adopt the M3 standard 28 dp corner radius; compact items
/// use 16 dp; small chips/badges use 12 dp.
@immutable
class AppSurfaces extends ThemeExtension<AppSurfaces> {
const AppSurfaces({
required this.cardRadius,
required this.compactCardRadius,
required this.containerRadius,
required this.dialogRadius,
required this.chipRadius,
});
/// Standard card radius 16 dp (M3 medium shape).
final double cardRadius;
/// Compact card radius for dense list tiles 12 dp.
final double compactCardRadius;
/// Large container radius 28 dp (M3 Expressive).
final double containerRadius;
/// Dialog / bottom-sheet radius 28 dp.
final double dialogRadius;
/// Chip / badge radius 12 dp.
final double chipRadius;
// convenience shapes
RoundedRectangleBorder get standardShape =>
RoundedRectangleBorder(borderRadius: BorderRadius.circular(cardRadius));
RoundedRectangleBorder get compactShape => RoundedRectangleBorder(
borderRadius: BorderRadius.circular(compactCardRadius),
);
RoundedRectangleBorder get containerShape => RoundedRectangleBorder(
borderRadius: BorderRadius.circular(containerRadius),
);
RoundedRectangleBorder get dialogShape =>
RoundedRectangleBorder(borderRadius: BorderRadius.circular(dialogRadius));
static AppSurfaces of(BuildContext context) {
final ext = Theme.of(context).extension<AppSurfaces>();
return ext ??
const AppSurfaces(
cardRadius: 16,
compactCardRadius: 12,
containerRadius: 28,
dialogRadius: 28,
chipRadius: 12,
);
}
@override
AppSurfaces copyWith({
double? cardRadius,
double? compactCardRadius,
double? containerRadius,
double? dialogRadius,
double? chipRadius,
}) {
return AppSurfaces(
cardRadius: cardRadius ?? this.cardRadius,
compactCardRadius: compactCardRadius ?? this.compactCardRadius,
containerRadius: containerRadius ?? this.containerRadius,
dialogRadius: dialogRadius ?? this.dialogRadius,
chipRadius: chipRadius ?? this.chipRadius,
);
}
@override
AppSurfaces lerp(ThemeExtension<AppSurfaces>? other, double t) {
if (other is! AppSurfaces) return this;
return AppSurfaces(
cardRadius: _lerpDouble(cardRadius, other.cardRadius, t),
compactCardRadius: _lerpDouble(
compactCardRadius,
other.compactCardRadius,
t,
),
containerRadius: _lerpDouble(containerRadius, other.containerRadius, t),
dialogRadius: _lerpDouble(dialogRadius, other.dialogRadius, t),
chipRadius: _lerpDouble(chipRadius, other.chipRadius, t),
);
}
}
double _lerpDouble(double a, double b, double t) => a + (b - a) * t;