Skip to content

Commit 6b8b927

Browse files
authored
[material_ui] Migrate M3 Drawer template to use new gen_defaults (flutter#12916)
Work toward flutter#187899. Fixes flutter#188413. This PR migrates the M3 Drawer defaults template to the new packages/material_ui/tool/gen_defaults generator. ## Pre-Review Checklist
1 parent 897192a commit 6b8b927

5 files changed

Lines changed: 38 additions & 69 deletions

File tree

‎packages/material_ui/lib/src/drawer.dart‎

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import 'material.dart';
2727
import 'material_localizations.dart';
2828
import 'theme.dart';
2929

30+
part 'generated/drawer_defaults_m3.g.dart';
31+
3032
// Examples can assume:
3133
// late BuildContext context;
3234

@@ -809,52 +811,3 @@ class _DrawerDefaultsM2 extends DrawerThemeData {
809811
@override
810812
Color? get shadowColor => Theme.of(context).shadowColor;
811813
}
812-
813-
// BEGIN GENERATED TOKEN PROPERTIES - Drawer
814-
815-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
816-
// "END GENERATED" comments are generated from data in the Material
817-
// Design token database by the script:
818-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
819-
820-
// dart format off
821-
class _DrawerDefaultsM3 extends DrawerThemeData {
822-
_DrawerDefaultsM3(this.context)
823-
: super(
824-
elevation: 1.0,
825-
clipBehavior: Clip.hardEdge,
826-
);
827-
828-
final BuildContext context;
829-
late final TextDirection direction = Directionality.of(context);
830-
831-
@override
832-
Color? get backgroundColor => Theme.of(context).colorScheme.surfaceContainerLow;
833-
834-
@override
835-
Color? get surfaceTintColor => Colors.transparent;
836-
837-
@override
838-
Color? get shadowColor => Colors.transparent;
839-
840-
// There isn't currently a token for this value, but it is shown in the spec,
841-
// so hard coding here for now.
842-
@override
843-
ShapeBorder? get shape => RoundedRectangleBorder(
844-
borderRadius: const BorderRadiusDirectional.horizontal(
845-
end: Radius.circular(16.0),
846-
).resolve(direction),
847-
);
848-
849-
// There isn't currently a token for this value, but it is shown in the spec,
850-
// so hard coding here for now.
851-
@override
852-
ShapeBorder? get endShape => RoundedRectangleBorder(
853-
borderRadius: const BorderRadiusDirectional.horizontal(
854-
start: Radius.circular(16.0),
855-
).resolve(direction),
856-
);
857-
}
858-
// dart format on
859-
860-
// END GENERATED TOKEN PROPERTIES - Drawer

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/drawer_defaults.g.dart renamed to packages/material_ui/lib/src/generated/drawer_defaults_m3.g.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// Do not edit by hand. The code is generated from data in the Material
6+
// Design token database by the script:
7+
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
8+
part of '../drawer.dart';
9+
510
class _DrawerDefaultsM3 extends DrawerThemeData {
611
_DrawerDefaultsM3(this.context) : super(elevation: 1.0, clipBehavior: Clip.hardEdge);
712

@@ -21,17 +26,15 @@ class _DrawerDefaultsM3 extends DrawerThemeData {
2126
// so hard coding here for now.
2227
@override
2328
ShapeBorder? get shape => RoundedRectangleBorder(
24-
borderRadius: const BorderRadiusDirectional.horizontal(
25-
end: Radius.circular(16.0),
26-
).resolve(direction),
29+
borderRadius: const BorderRadiusDirectional.horizontal(end: Radius.circular(16.0))
30+
.resolve(direction),
2731
);
2832

2933
// There isn't currently a token for this value, but it is shown in the spec,
3034
// so hard coding here for now.
3135
@override
3236
ShapeBorder? get endShape => RoundedRectangleBorder(
33-
borderRadius: const BorderRadiusDirectional.horizontal(
34-
start: Radius.circular(16.0),
35-
).resolve(direction),
37+
borderRadius: const BorderRadiusDirectional.horizontal(start: Radius.circular(16.0))
38+
.resolve(direction),
3639
);
3740
}

‎packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import '../templates/color_scheme_template.dart';
2626
// import '../templates/date_picker_template.dart';
2727
// import '../templates/dialog_template.dart';
2828
import '../templates/divider_template.dart';
29+
import '../templates/drawer_template.dart';
2930

30-
// import '../templates/drawer_template.dart';
3131
// import '../templates/expansion_tile_template.dart';
3232
// import '../templates/fab_template.dart';
3333
import '../templates/filter_chip_template.dart';
@@ -86,7 +86,7 @@ Future<void> main(List<String> args) async {
8686
// const DatePickerTemplateM3().generateFile(verbose: verbose);
8787
// const DialogTemplateM3().generateFile(verbose: verbose);
8888
const DividerTemplateM3().generateFile(verbose: verbose);
89-
// const DrawerTemplateM3().generateFile(verbose: verbose);
89+
const DrawerTemplateM3().generateFile(verbose: verbose);
9090
// const ExpansionTileTemplateM3().generateFile(verbose: verbose);
9191
// const FabTemplateM3().generateFile(verbose: verbose);
9292
const FilterChipTemplateM3().generateFile(verbose: verbose);

packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/drawer_template.dart renamed to packages/material_ui/tool/gen_defaults/templates/drawer_template.dart

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import '../data/navigation_drawer.dart';
56
import 'template.dart';
67

7-
class DrawerTemplate extends TokenTemplate {
8-
const DrawerTemplate(super.blockName, super.fileName, super.tokens);
8+
class DrawerTemplateM3 extends TokenTemplateM3 {
9+
const DrawerTemplateM3();
910

1011
@override
11-
String generate() =>
12+
String get name => 'Drawer';
13+
14+
@override
15+
String get parentFilePath => 'drawer.dart';
16+
17+
@override
18+
String generateContents(String className) =>
1219
'''
13-
class _${blockName}DefaultsM3 extends DrawerThemeData {
14-
_${blockName}DefaultsM3(this.context)
20+
class $className extends DrawerThemeData {
21+
$className(this.context)
1522
: super(
16-
elevation: ${elevation("md.comp.navigation-drawer.modal.container")},
23+
elevation: ${number(TokenNavigationDrawer.modalContainerElevation)},
1724
clipBehavior: Clip.hardEdge,
1825
);
1926
2027
final BuildContext context;
2128
late final TextDirection direction = Directionality.of(context);
2229
2330
@override
24-
Color? get backgroundColor => ${componentColor("md.comp.navigation-drawer.modal.container")};
31+
Color? get backgroundColor => ${color(TokenNavigationDrawer.modalContainerColor, 'Theme.of(context).colorScheme')};
2532
2633
@override
27-
Color? get surfaceTintColor => ${colorOrTransparent("md.comp.navigation-drawer.container.surface-tint-layer.color")};
34+
Color? get surfaceTintColor => Colors.transparent;
2835
2936
@override
30-
Color? get shadowColor => ${colorOrTransparent("md.comp.navigation-drawer.container.shadow-color")};
37+
Color? get shadowColor => Colors.transparent;
3138
3239
// There isn't currently a token for this value, but it is shown in the spec,
3340
// so hard coding here for now.

‎packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import '../templates/color_scheme_template.dart';
2323
// import '../templates/date_picker_template.dart';
2424
// import '../templates/dialog_template.dart';
2525
import '../templates/divider_template.dart';
26-
// import '../templates/drawer_template.dart';
26+
import '../templates/drawer_template.dart';
2727
// import '../templates/expansion_tile_template.dart';
2828
// import '../templates/fab_template.dart';
2929
import '../templates/filter_chip_template.dart';
@@ -562,8 +562,14 @@ void main() {
562562
});
563563

564564
test('DrawerTemplateM3 emits M3 Drawer defaults from tokens', () {
565-
// Intentionally empty, will be implemented during migration. See:
566-
// https://github.com/flutter/flutter/issues/187899
565+
final String contents = _generateContents(const DrawerTemplateM3());
566+
expect(contents, contains('class _DrawerDefaultsM3 extends DrawerThemeData'));
567+
expect(contents, contains('elevation: 1.0'));
568+
expect(
569+
contents,
570+
contains('Color? get backgroundColor => Theme.of(context).colorScheme.surfaceContainerLow'),
571+
);
572+
expect(contents, contains('ShapeBorder? get endShape => RoundedRectangleBorder('));
567573
});
568574

569575
test('ExpansionTileTemplateM3 emits M3 ExpansionTile defaults from tokens', () {

0 commit comments

Comments
 (0)