@@ -43,6 +43,8 @@ import 'text_theme.dart';
4343import 'theme.dart' ;
4444import 'theme_data.dart' ;
4545
46+ part 'generated/menu_defaults_m3.g.dart' ;
47+
4648// Examples can assume:
4749// bool _throwShotAway = false;
4850// late BuildContext context;
@@ -4071,260 +4073,3 @@ bool get _platformSupportsAccelerators {
40714073 // platforms.
40724074 return ! _isCupertino;
40734075}
4074-
4075- // BEGIN GENERATED TOKEN PROPERTIES - Menu
4076-
4077- // Do not edit by hand. The code between the "BEGIN GENERATED" and
4078- // "END GENERATED" comments are generated from data in the Material
4079- // Design token database by the script:
4080- // dev/tools/gen_defaults/bin/gen_defaults.dart.
4081-
4082- // dart format off
4083- class _MenuBarDefaultsM3 extends MenuStyle {
4084- _MenuBarDefaultsM3 (this .context)
4085- : super (
4086- elevation: const MaterialStatePropertyAll <double ?>(3.0 ),
4087- shape: const MaterialStatePropertyAll <OutlinedBorder >(_defaultMenuBorder),
4088- alignment: AlignmentDirectional .bottomStart,
4089- );
4090-
4091- static const RoundedRectangleBorder _defaultMenuBorder =
4092- RoundedRectangleBorder (borderRadius: BorderRadius .all (Radius .circular (4.0 )));
4093-
4094- final BuildContext context;
4095-
4096- late final ColorScheme _colors = Theme .of (context).colorScheme;
4097-
4098- @override
4099- WidgetStateProperty <Color ?> get backgroundColor {
4100- return MaterialStatePropertyAll <Color ?>(_colors.surfaceContainer);
4101- }
4102-
4103- @override
4104- WidgetStateProperty <Color ?>? get shadowColor {
4105- return MaterialStatePropertyAll <Color ?>(_colors.shadow);
4106- }
4107-
4108- @override
4109- WidgetStateProperty <Color ?>? get surfaceTintColor {
4110- return const MaterialStatePropertyAll <Color ?>(Colors .transparent);
4111- }
4112-
4113- @override
4114- WidgetStateProperty <EdgeInsetsGeometry ?>? get padding {
4115- return const MaterialStatePropertyAll <EdgeInsetsGeometry >(
4116- EdgeInsetsDirectional .symmetric (
4117- horizontal: _kTopLevelMenuHorizontalMinPadding
4118- ),
4119- );
4120- }
4121-
4122- @override
4123- VisualDensity get visualDensity => Theme .of (context).visualDensity;
4124- }
4125-
4126- class _MenuButtonDefaultsM3 extends ButtonStyle {
4127- _MenuButtonDefaultsM3 (this .context)
4128- : super (
4129- animationDuration: kThemeChangeDuration,
4130- enableFeedback: true ,
4131- alignment: AlignmentDirectional .centerStart,
4132- );
4133-
4134- final BuildContext context;
4135-
4136- late final ColorScheme _colors = Theme .of (context).colorScheme;
4137- late final TextTheme _textTheme = Theme .of (context).textTheme;
4138-
4139- @override
4140- WidgetStateProperty <Color ?>? get backgroundColor {
4141- return ButtonStyleButton .allOrNull <Color >(Colors .transparent);
4142- }
4143-
4144- // No default shadow color
4145-
4146- // No default surface tint color
4147-
4148- @override
4149- WidgetStateProperty <double >? get elevation {
4150- return ButtonStyleButton .allOrNull <double >(0.0 );
4151- }
4152-
4153- @override
4154- WidgetStateProperty <Color ?>? get foregroundColor {
4155- return WidgetStateProperty .resolveWith ((Set <WidgetState > states) {
4156- if (states.contains (WidgetState .disabled)) {
4157- return _colors.onSurface.withOpacity (0.38 );
4158- }
4159- if (states.contains (WidgetState .pressed)) {
4160- return _colors.onSurface;
4161- }
4162- if (states.contains (WidgetState .hovered)) {
4163- return _colors.onSurface;
4164- }
4165- if (states.contains (WidgetState .focused)) {
4166- return _colors.onSurface;
4167- }
4168- return _colors.onSurface;
4169- });
4170- }
4171-
4172- @override
4173- WidgetStateProperty <Color ?>? get iconColor {
4174- return WidgetStateProperty .resolveWith ((Set <WidgetState > states) {
4175- if (states.contains (WidgetState .disabled)) {
4176- return _colors.onSurface.withOpacity (0.38 );
4177- }
4178- if (states.contains (WidgetState .pressed)) {
4179- return _colors.onSurfaceVariant;
4180- }
4181- if (states.contains (WidgetState .hovered)) {
4182- return _colors.onSurfaceVariant;
4183- }
4184- if (states.contains (WidgetState .focused)) {
4185- return _colors.onSurfaceVariant;
4186- }
4187- return _colors.onSurfaceVariant;
4188- });
4189- }
4190-
4191- // No default fixedSize
4192-
4193- @override
4194- WidgetStateProperty <double >? get iconSize {
4195- return const MaterialStatePropertyAll <double >(24.0 );
4196- }
4197-
4198- @override
4199- WidgetStateProperty <Size >? get maximumSize {
4200- return ButtonStyleButton .allOrNull <Size >(Size .infinite);
4201- }
4202-
4203- @override
4204- WidgetStateProperty <Size >? get minimumSize {
4205- return ButtonStyleButton .allOrNull <Size >(const Size (64.0 , 48.0 ));
4206- }
4207-
4208- @override
4209- WidgetStateProperty <MouseCursor ?>? get mouseCursor => WidgetStateMouseCursor .adaptiveClickable;
4210-
4211- @override
4212- WidgetStateProperty <Color ?>? get overlayColor {
4213- return WidgetStateProperty .resolveWith (
4214- (Set <WidgetState > states) {
4215- if (states.contains (WidgetState .pressed)) {
4216- return _colors.onSurface.withOpacity (0.1 );
4217- }
4218- if (states.contains (WidgetState .hovered)) {
4219- return _colors.onSurface.withOpacity (0.08 );
4220- }
4221- if (states.contains (WidgetState .focused)) {
4222- return _colors.onSurface.withOpacity (0.1 );
4223- }
4224- return Colors .transparent;
4225- },
4226- );
4227- }
4228-
4229- @override
4230- WidgetStateProperty <EdgeInsetsGeometry >? get padding {
4231- return ButtonStyleButton .allOrNull <EdgeInsetsGeometry >(_scaledPadding (context));
4232- }
4233-
4234- // No default side
4235-
4236- @override
4237- WidgetStateProperty <OutlinedBorder >? get shape {
4238- return ButtonStyleButton .allOrNull <OutlinedBorder >(const RoundedRectangleBorder ());
4239- }
4240-
4241- @override
4242- InteractiveInkFeatureFactory ? get splashFactory => Theme .of (context).splashFactory;
4243-
4244- @override
4245- MaterialTapTargetSize ? get tapTargetSize => Theme .of (context).materialTapTargetSize;
4246-
4247- @override
4248- WidgetStateProperty <TextStyle ?> get textStyle {
4249- // TODO(tahatesser): This is taken from https://m3.material.io/components/menus/specs
4250- // Update this when the token is available.
4251- return MaterialStatePropertyAll <TextStyle ?>(_textTheme.labelLarge);
4252- }
4253-
4254- @override
4255- VisualDensity ? get visualDensity => Theme .of (context).visualDensity;
4256-
4257- // The horizontal padding number comes from the spec.
4258- EdgeInsetsGeometry _scaledPadding (BuildContext context) {
4259- VisualDensity visualDensity = Theme .of (context).visualDensity;
4260- // When horizontal VisualDensity is greater than zero, set it to zero
4261- // because the [ButtonStyleButton] has already handle the padding based on the density.
4262- // However, the [ButtonStyleButton] doesn't allow the [VisualDensity] adjustment
4263- // to reduce the width of the left/right padding, so we need to handle it here if
4264- // the density is less than zero, such as on desktop platforms.
4265- if (visualDensity.horizontal > 0 ) {
4266- visualDensity = VisualDensity (vertical: visualDensity.vertical);
4267- }
4268- // Since the threshold paddings used below are empirical values determined
4269- // at a font size of 14.0, 14.0 is used as the base value for scaling the
4270- // padding.
4271- final double fontSize = Theme .of (context).textTheme.labelLarge? .fontSize ?? 14.0 ;
4272- final double fontSizeRatio = MediaQuery .textScalerOf (context).scale (fontSize) / 14.0 ;
4273- return ButtonStyleButton .scaledPadding (
4274- EdgeInsets .symmetric (horizontal: math.max (
4275- _kMenuViewPadding,
4276- _kLabelItemDefaultSpacing + visualDensity.baseSizeAdjustment.dx,
4277- )),
4278- EdgeInsets .symmetric (horizontal: math.max (
4279- _kMenuViewPadding,
4280- 8 + visualDensity.baseSizeAdjustment.dx,
4281- )),
4282- const EdgeInsets .symmetric (horizontal: _kMenuViewPadding),
4283- fontSizeRatio,
4284- );
4285- }
4286- }
4287-
4288- class _MenuDefaultsM3 extends MenuStyle {
4289- _MenuDefaultsM3 (this .context)
4290- : super (
4291- elevation: const MaterialStatePropertyAll <double ?>(3.0 ),
4292- shape: const MaterialStatePropertyAll <OutlinedBorder >(_defaultMenuBorder),
4293- alignment: AlignmentDirectional .topEnd,
4294- );
4295-
4296- static const RoundedRectangleBorder _defaultMenuBorder =
4297- RoundedRectangleBorder (borderRadius: BorderRadius .all (Radius .circular (4.0 )));
4298-
4299- final BuildContext context;
4300-
4301- late final ColorScheme _colors = Theme .of (context).colorScheme;
4302-
4303- @override
4304- WidgetStateProperty <Color ?> get backgroundColor {
4305- return MaterialStatePropertyAll <Color ?>(_colors.surfaceContainer);
4306- }
4307-
4308- @override
4309- WidgetStateProperty <Color ?>? get surfaceTintColor {
4310- return const MaterialStatePropertyAll <Color ?>(Colors .transparent);
4311- }
4312-
4313- @override
4314- WidgetStateProperty <Color ?>? get shadowColor {
4315- return MaterialStatePropertyAll <Color ?>(_colors.shadow);
4316- }
4317-
4318- @override
4319- WidgetStateProperty <EdgeInsetsGeometry ?>? get padding {
4320- return const MaterialStatePropertyAll <EdgeInsetsGeometry >(
4321- EdgeInsetsDirectional .symmetric (vertical: _kMenuVerticalMinPadding),
4322- );
4323- }
4324-
4325- @override
4326- VisualDensity get visualDensity => Theme .of (context).visualDensity;
4327- }
4328- // dart format on
4329-
4330- // END GENERATED TOKEN PROPERTIES - Menu
0 commit comments