Skip to content

Commit 46c8280

Browse files
authored
[material_ui] Migrate M3 Dialog template to use new gen_defaults (flutter#12917)
Work toward flutter/flutter#187899. Fixes flutter/flutter#188411. This PR migrates the M3 Dialog defaults template to the new packages/material_ui/tool/gen_defaults generator. ## Pre-Review Checklist
1 parent bbc191c commit 46c8280

7 files changed

Lines changed: 114 additions & 143 deletions

File tree

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

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import 'material_localizations.dart';
2525
import 'text_theme.dart';
2626
import 'theme.dart';
2727

28+
part 'generated/dialog_defaults_m3.g.dart';
29+
part 'generated/dialog_fullscreen_defaults_m3.g.dart';
30+
2831
// Examples can assume:
2932
// enum Department { treasury, state }
3033
// late BuildContext context;
@@ -1981,69 +1984,3 @@ class _DialogDefaultsM2 extends DialogThemeData {
19811984
@override
19821985
EdgeInsetsGeometry? get actionsPadding => EdgeInsets.zero;
19831986
}
1984-
1985-
// BEGIN GENERATED TOKEN PROPERTIES - DialogFullscreen
1986-
1987-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
1988-
// "END GENERATED" comments are generated from data in the Material
1989-
// Design token database by the script:
1990-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
1991-
1992-
// dart format off
1993-
class _DialogFullscreenDefaultsM3 extends DialogThemeData {
1994-
const _DialogFullscreenDefaultsM3(this.context): super(clipBehavior: Clip.none);
1995-
1996-
final BuildContext context;
1997-
1998-
@override
1999-
Color? get backgroundColor => Theme.of(context).colorScheme.surface;
2000-
}
2001-
// dart format on
2002-
2003-
// END GENERATED TOKEN PROPERTIES - DialogFullscreen
2004-
2005-
// BEGIN GENERATED TOKEN PROPERTIES - Dialog
2006-
2007-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
2008-
// "END GENERATED" comments are generated from data in the Material
2009-
// Design token database by the script:
2010-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
2011-
2012-
// dart format off
2013-
class _DialogDefaultsM3 extends DialogThemeData {
2014-
_DialogDefaultsM3(this.context)
2015-
: super(
2016-
alignment: Alignment.center,
2017-
elevation: 6.0,
2018-
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))),
2019-
clipBehavior: Clip.none,
2020-
);
2021-
2022-
final BuildContext context;
2023-
late final ColorScheme _colors = Theme.of(context).colorScheme;
2024-
late final TextTheme _textTheme = Theme.of(context).textTheme;
2025-
2026-
@override
2027-
Color? get iconColor => _colors.secondary;
2028-
2029-
@override
2030-
Color? get backgroundColor => _colors.surfaceContainerHigh;
2031-
2032-
@override
2033-
Color? get shadowColor => Colors.transparent;
2034-
2035-
@override
2036-
Color? get surfaceTintColor => Colors.transparent;
2037-
2038-
@override
2039-
TextStyle? get titleTextStyle => _textTheme.headlineSmall;
2040-
2041-
@override
2042-
TextStyle? get contentTextStyle => _textTheme.bodyMedium;
2043-
2044-
@override
2045-
EdgeInsetsGeometry? get actionsPadding => const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0);
2046-
}
2047-
// dart format on
2048-
2049-
// END GENERATED TOKEN PROPERTIES - Dialog

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/dialog_defaults.g.dart renamed to packages/material_ui/lib/src/generated/dialog_defaults_m3.g.dart

Lines changed: 5 additions & 0 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 '../dialog.dart';
9+
510
class _DialogDefaultsM3 extends DialogThemeData {
611
_DialogDefaultsM3(this.context)
712
: super(

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/dialog_fullscreen_defaults.g.dart renamed to packages/material_ui/lib/src/generated/dialog_fullscreen_defaults_m3.g.dart

Lines changed: 5 additions & 0 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 '../dialog.dart';
9+
510
class _DialogFullscreenDefaultsM3 extends DialogThemeData {
611
const _DialogFullscreenDefaultsM3(this.context) : super(clipBehavior: Clip.none);
712

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import '../templates/checkbox_template.dart';
2424
import '../templates/chip_template.dart';
2525
import '../templates/color_scheme_template.dart';
2626
import '../templates/date_picker_template.dart';
27-
28-
// import '../templates/dialog_template.dart';
27+
import '../templates/dialog_template.dart';
2928
import '../templates/divider_template.dart';
3029
import '../templates/drawer_template.dart';
3130
import '../templates/expansion_tile_template.dart';
@@ -83,7 +82,8 @@ Future<void> main(List<String> args) async {
8382
const ChipTemplateM3().generateFile(verbose: verbose);
8483
const ColorSchemeTemplateM3().generateFile(verbose: verbose);
8584
const DatePickerTemplateM3().generateFile(verbose: verbose);
86-
// const DialogTemplateM3().generateFile(verbose: verbose);
85+
const DialogTemplateM3().generateFile(verbose: verbose);
86+
const DialogFullscreenTemplateM3().generateFile(verbose: verbose);
8787
const DividerTemplateM3().generateFile(verbose: verbose);
8888
const DrawerTemplateM3().generateFile(verbose: verbose);
8989
const ExpansionTileTemplateM3().generateFile(verbose: verbose);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import '../data/dialog.dart';
6+
import '../data/full_screen_dialog.dart';
7+
import 'template.dart';
8+
9+
class DialogTemplateM3 extends TokenTemplateM3 {
10+
const DialogTemplateM3();
11+
12+
@override
13+
String get name => 'Dialog';
14+
15+
@override
16+
String get parentFilePath => 'dialog.dart';
17+
18+
@override
19+
String generateContents(String className) =>
20+
'''
21+
class $className extends DialogThemeData {
22+
$className(this.context)
23+
: super(
24+
alignment: Alignment.center,
25+
elevation: ${number(TokenDialog.containerElevation)},
26+
shape: ${shape(TokenDialog.containerShape)},
27+
clipBehavior: Clip.none,
28+
);
29+
30+
final BuildContext context;
31+
late final ColorScheme _colors = Theme.of(context).colorScheme;
32+
late final TextTheme _textTheme = Theme.of(context).textTheme;
33+
34+
@override
35+
Color? get iconColor => ${color(TokenDialog.withIconIconColor)};
36+
37+
@override
38+
Color? get backgroundColor => ${color(TokenDialog.containerColor)};
39+
40+
@override
41+
Color? get shadowColor => Colors.transparent;
42+
43+
@override
44+
Color? get surfaceTintColor => Colors.transparent;
45+
46+
@override
47+
TextStyle? get titleTextStyle => ${textStyle(TokenDialog.headlineType, '_textTheme')};
48+
49+
@override
50+
TextStyle? get contentTextStyle => ${textStyle(TokenDialog.supportingTextType, '_textTheme')};
51+
52+
@override
53+
EdgeInsetsGeometry? get actionsPadding => const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0);
54+
}
55+
''';
56+
}
57+
58+
class DialogFullscreenTemplateM3 extends TokenTemplateM3 {
59+
const DialogFullscreenTemplateM3();
60+
61+
@override
62+
String get name => 'Dialog Fullscreen';
63+
64+
@override
65+
String get parentFilePath => 'dialog.dart';
66+
67+
@override
68+
String generateContents(String className) =>
69+
'''
70+
class $className extends DialogThemeData {
71+
const $className(this.context): super(clipBehavior: Clip.none);
72+
73+
final BuildContext context;
74+
75+
@override
76+
Color? get backgroundColor => ${color(TokenFullScreenDialog.containerColor, 'Theme.of(context).colorScheme')};
77+
}
78+
''';
79+
}

‎packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/dialog_template.dart‎

Lines changed: 0 additions & 71 deletions
This file was deleted.

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import '../templates/checkbox_template.dart';
2121
import '../templates/chip_template.dart';
2222
import '../templates/color_scheme_template.dart';
2323
import '../templates/date_picker_template.dart';
24-
// import '../templates/dialog_template.dart';
24+
import '../templates/dialog_template.dart';
2525
import '../templates/divider_template.dart';
2626
import '../templates/drawer_template.dart';
2727
import '../templates/expansion_tile_template.dart';
@@ -559,8 +559,24 @@ void main() {
559559
});
560560

561561
test('DialogTemplateM3 emits M3 Dialog defaults from tokens', () {
562-
// Intentionally empty, will be implemented during migration. See:
563-
// https://github.com/flutter/flutter/issues/187899
562+
final String contents = _generateContents(const DialogTemplateM3());
563+
expect(contents, contains('class _DialogDefaultsM3 extends DialogThemeData'));
564+
expect(
565+
contents,
566+
contains(
567+
'shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0)))',
568+
),
569+
);
570+
expect(contents, contains('Color? get backgroundColor => _colors.surfaceContainerHigh'));
571+
572+
final String fullscreenContents = _generateContents(const DialogFullscreenTemplateM3());
573+
expect(
574+
fullscreenContents,
575+
allOf(
576+
contains('class _DialogFullscreenDefaultsM3 extends DialogThemeData'),
577+
contains('Color? get backgroundColor => Theme.of(context).colorScheme.surface'),
578+
),
579+
);
564580
});
565581

566582
test('DividerTemplateM3 emits M3 Divider defaults from tokens', () {

0 commit comments

Comments
 (0)