Files
SpotiFLAC-Mobile/lib/widgets/expressive_button.dart
T
zarzet 962e582acc chore(flutter): move to Flutter 3.50.0 and the material_ui packages
Flutter 3.50 deprecates its built-in Material and Cupertino libraries in
favour of the material_ui and cupertino_ui packages. The imports move
with the official fix (dart fix, migrate_design_widgets); the app's old
two-library theme bridge collapses into one Theme type.

- MaterialExpressiveScope keeps the complete host theme nearest its
  child. The reduced copy made for the expressive widgets now shares the
  app's Theme type and would hide component themes and extensions.
- LegacyThemeBrightness hands the brightness to the glass package, which
  still reads Flutter's built-in theme.
- appLocalizationsDelegates lists the material_ui localization delegates;
  the generated list still names the built-in ones.
- Tests: findByTooltip and pageBack replace the flutter_test helpers that
  only know the built-in widgets, and several tests that had gone stale
  against earlier app changes are repaired.
2026-11-15 23:33:29 +07:00

118 lines
3.4 KiB
Dart

import 'package:material_ui/material_ui.dart';
import 'package:material_3_expressive/material_3_expressive.dart';
import 'package:mornye/theme/material_expressive.dart';
import 'package:mornye/widgets/app_icon.dart';
/// Expressive actions retain caller colors, disabled states and flexible labels.
class ExpressiveButton extends StatelessWidget {
const ExpressiveButton({
super.key,
required this.onPressed,
required this.child,
this.icon,
this.style,
this.outlined = false,
this.tonal = false,
this.text = false,
});
final VoidCallback? onPressed;
final Widget child;
final Widget? icon;
final ButtonStyle? style;
final bool outlined;
final bool tonal;
/// Low-emphasis action without a container, like [TextButton].
final bool text;
@override
Widget build(BuildContext context) {
final icon = this.icon == null ? null : symbolIconWidget(this.icon!);
if (!materialExpressiveEnabled(context)) {
if (icon != null) {
// Keep the standard icon spacing and asymmetric padding.
if (text) {
return TextButton.icon(
onPressed: onPressed,
style: style,
icon: icon,
label: child,
);
}
if (outlined) {
return OutlinedButton.icon(
onPressed: onPressed,
style: style,
icon: icon,
label: child,
);
}
if (tonal) {
return FilledButton.tonalIcon(
onPressed: onPressed,
style: style,
icon: icon,
label: child,
);
}
return FilledButton.icon(
onPressed: onPressed,
style: style,
icon: icon,
label: child,
);
}
if (text) {
return TextButton(onPressed: onPressed, style: style, child: child);
}
if (outlined) {
return OutlinedButton(onPressed: onPressed, style: style, child: child);
}
if (tonal) {
return FilledButton.tonal(
onPressed: onPressed,
style: style,
child: child,
);
}
return FilledButton(onPressed: onPressed, style: style, child: child);
}
final content = Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (icon != null) ...[icon, const SizedBox(width: 8)],
Flexible(child: child),
],
);
final states = <WidgetState>{if (onPressed == null) WidgetState.disabled};
return MaterialExpressiveScope(
child: M3EButton(
onPressed: onPressed,
style: text
? M3EButtonStyle.text
: outlined
? M3EButtonStyle.outlined
: tonal
? M3EButtonStyle.tonal
: M3EButtonStyle.filled,
decoration: M3EButtonDecoration(
backgroundColor: style?.backgroundColor,
foregroundColor: style?.foregroundColor,
overlayColor: style?.overlayColor,
side: style?.side,
minimumSize:
style?.minimumSize?.resolve(states) ?? const Size(48, 48),
maximumSize: style?.maximumSize?.resolve(states),
fixedSize: style?.fixedSize?.resolve(states),
padding: style?.padding?.resolve(states),
textStyle: style?.textStyle?.resolve(states),
iconSize: style?.iconSize?.resolve(states),
),
child: content,
),
);
}
}