Update Popup Menu to support Material 3 (#103606)
This commit is contained in:
@@ -33,6 +33,7 @@ import 'package:gen_defaults/input_chip_template.dart';
|
||||
import 'package:gen_defaults/input_decorator_template.dart';
|
||||
import 'package:gen_defaults/navigation_bar_template.dart';
|
||||
import 'package:gen_defaults/navigation_rail_template.dart';
|
||||
import 'package:gen_defaults/popup_menu_template.dart';
|
||||
import 'package:gen_defaults/progress_indicator_template.dart';
|
||||
import 'package:gen_defaults/radio_template.dart';
|
||||
import 'package:gen_defaults/surface_tint.dart';
|
||||
@@ -136,6 +137,7 @@ Future<void> main(List<String> args) async {
|
||||
InputDecoratorTemplate('InputDecorator', '$materialLib/input_decorator.dart', tokens).updateFile();
|
||||
NavigationBarTemplate('NavigationBar', '$materialLib/navigation_bar.dart', tokens).updateFile();
|
||||
NavigationRailTemplate('NavigationRail', '$materialLib/navigation_rail.dart', tokens).updateFile();
|
||||
PopupMenuTemplate('PopupMenu', '$materialLib/popup_menu.dart', tokens).updateFile();
|
||||
ProgressIndicatorTemplate('ProgressIndicator', '$materialLib/progress_indicator.dart', tokens).updateFile();
|
||||
RadioTemplate('Radio<T>', '$materialLib/radio.dart', tokens).updateFile();
|
||||
SurfaceTintTemplate('SurfaceTint', '$materialLib/elevation_overlay.dart', tokens).updateFile();
|
||||
|
||||
46
dev/tools/gen_defaults/lib/popup_menu_template.dart
Normal file
46
dev/tools/gen_defaults/lib/popup_menu_template.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'template.dart';
|
||||
|
||||
class PopupMenuTemplate extends TokenTemplate {
|
||||
const PopupMenuTemplate(super.blockName, super.fileName, super.tokens, {
|
||||
super.colorSchemePrefix = '_colors.',
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
@override
|
||||
String generate() => '''
|
||||
class _${blockName}DefaultsM3 extends PopupMenuThemeData {
|
||||
_${blockName}DefaultsM3(this.context)
|
||||
: super(elevation: ${elevation('md.comp.menu.container')});
|
||||
|
||||
final BuildContext context;
|
||||
late final ThemeData _theme = Theme.of(context);
|
||||
late final ColorScheme _colors = _theme.colorScheme;
|
||||
late final TextTheme _textTheme = _theme.textTheme;
|
||||
|
||||
@override MaterialStateProperty<TextStyle?>? get labelTextStyle {
|
||||
return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
final TextStyle style = _textTheme.labelLarge!;
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return style.apply(color: ${componentColor('md.comp.menu.list-item.disabled.label-text')});
|
||||
}
|
||||
return style.apply(color: ${componentColor('md.comp.menu.list-item.label-text')});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Color? get color => ${componentColor('md.comp.menu.container')};
|
||||
|
||||
@override
|
||||
Color? get shadowColor => ${color("md.comp.menu.container.shadow-color")};
|
||||
|
||||
@override
|
||||
Color? get surfaceTintColor => ${color("md.comp.menu.container.surface-tint-layer.color")};
|
||||
|
||||
@override
|
||||
ShapeBorder? get shape => ${shape("md.comp.menu.container")};
|
||||
}''';
|
||||
}
|
||||
Reference in New Issue
Block a user