Skip to content

Commit 3f7a1d4

Browse files
authored
[material_ui] Migrate M3 Banner template to use new gen_defaults (flutter#12734)
Work towards flutter#191088 **Ports over flutter/packages#12227 which landed on the `m3e_migration` feature branch.** ### Original PR description Work towards flutter#187899 Fixes flutter#188402 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 93a0c53 commit 3f7a1d4

6 files changed

Lines changed: 60 additions & 78 deletions

File tree

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import 'scaffold.dart';
1818
import 'text_theme.dart';
1919
import 'theme.dart';
2020

21+
part 'generated/banner_defaults_m3.g.dart';
22+
2123
// Examples can assume:
2224
// late BuildContext context;
2325

@@ -501,35 +503,3 @@ class _BannerDefaultsM2 extends MaterialBannerThemeData {
501503
@override
502504
TextStyle? get contentTextStyle => _theme.textTheme.bodyMedium;
503505
}
504-
505-
// BEGIN GENERATED TOKEN PROPERTIES - Banner
506-
507-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
508-
// "END GENERATED" comments are generated from data in the Material
509-
// Design token database by the script:
510-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
511-
512-
// dart format off
513-
class _BannerDefaultsM3 extends MaterialBannerThemeData {
514-
_BannerDefaultsM3(this.context)
515-
: super(elevation: 1.0);
516-
517-
final BuildContext context;
518-
late final ColorScheme _colors = Theme.of(context).colorScheme;
519-
late final TextTheme _textTheme = Theme.of(context).textTheme;
520-
521-
@override
522-
Color? get backgroundColor => _colors.surfaceContainerLow;
523-
524-
@override
525-
Color? get surfaceTintColor => Colors.transparent;
526-
527-
@override
528-
Color? get dividerColor => _colors.outlineVariant;
529-
530-
@override
531-
TextStyle? get contentTextStyle => _textTheme.bodyMedium;
532-
}
533-
// dart format on
534-
535-
// END GENERATED TOKEN PROPERTIES - Banner

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/banner_defaults.g.dart renamed to packages/material_ui/lib/src/generated/banner_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 '../banner.dart';
9+
510
class _BannerDefaultsM3 extends MaterialBannerThemeData {
611
_BannerDefaultsM3(this.context) : super(elevation: 1.0);
712

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:args/args.dart';
1515
import '../templates/action_chip_template.dart';
1616
import '../templates/app_bar_template.dart';
1717
import '../templates/badge_template.dart';
18-
// import '../templates/banner_template.dart';
18+
import '../templates/banner_template.dart';
1919
// import '../templates/bottom_app_bar_template.dart';
2020
import '../templates/bottom_sheet_template.dart';
2121

@@ -67,7 +67,7 @@ Future<void> main(List<String> args) async {
6767
const ActionChipTemplateM3().generateFile(verbose: verbose);
6868
const AppBarTemplateM3().generateFile(verbose: verbose);
6969
const BadgeTemplateM3().generateFile(verbose: verbose);
70-
// const BannerTemplateM3().generateFile(verbose: verbose);
70+
const BannerTemplateM3().generateFile(verbose: verbose);
7171
// const BottomAppBarTemplateM3().generateFile(verbose: verbose);
7272
const BottomSheetTemplateM3().generateFile(verbose: verbose);
7373
// const ButtonTemplateM3().generateFile(verbose: verbose);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/banner.dart';
6+
import '../data/divider.dart';
7+
import 'template.dart';
8+
9+
class BannerTemplateM3 extends TokenTemplateM3 {
10+
const BannerTemplateM3();
11+
12+
@override
13+
String get name => 'Banner';
14+
15+
@override
16+
String get parentFilePath => 'banner.dart';
17+
18+
@override
19+
String generateContents(String className) =>
20+
'''
21+
class $className extends MaterialBannerThemeData {
22+
$className(this.context)
23+
: super(elevation: ${number(TokenBanner.containerElevation)});
24+
25+
final BuildContext context;
26+
late final ColorScheme _colors = Theme.of(context).colorScheme;
27+
late final TextTheme _textTheme = Theme.of(context).textTheme;
28+
29+
@override
30+
Color? get backgroundColor => ${color(TokenBanner.containerColor, '_colors')};
31+
32+
@override
33+
Color? get surfaceTintColor => Colors.transparent;
34+
35+
@override
36+
Color? get dividerColor => ${color(TokenDivider.color, '_colors')};
37+
38+
@override
39+
TextStyle? get contentTextStyle => ${textStyle(TokenBanner.supportingTextType, '_textTheme')};
40+
}
41+
''';
42+
}

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

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

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import '../data/typescale_emphasized.dart';
1212
import '../templates/action_chip_template.dart';
1313
import '../templates/app_bar_template.dart';
1414
import '../templates/badge_template.dart';
15-
// import '../templates/banner_template.dart';
15+
import '../templates/banner_template.dart';
1616
// import '../templates/bottom_app_bar_template.dart';
1717
import '../templates/bottom_sheet_template.dart';
1818
// import '../templates/button_template.dart';
@@ -258,9 +258,14 @@ void main() {
258258
);
259259
});
260260

261-
test('BannerTemplateM3 emits M3 Banner defaults from tokens', () {
262-
// Intentionally empty, will be implemented during migration. See:
263-
// https://github.com/flutter/flutter/issues/187899
261+
test('BannerTemplateM3 emits M3 Banner defaults from banner tokens', () {
262+
final String contents = const BannerTemplateM3().generateContents('_BannerDefaultsM3');
263+
expect(contents, contains('class _BannerDefaultsM3 extends MaterialBannerThemeData'));
264+
expect(contents, contains('elevation: 1.0'));
265+
expect(contents, contains('Color? get backgroundColor => _colors.surfaceContainerLow'));
266+
expect(contents, contains('Color? get surfaceTintColor => Colors.transparent'));
267+
expect(contents, contains('Color? get dividerColor => _colors.outlineVariant'));
268+
expect(contents, contains('TextStyle? get contentTextStyle => _textTheme.bodyMedium'));
264269
});
265270

266271
test('BottomAppBarTemplateM3 emits M3 BottomAppBar defaults from tokens', () {

0 commit comments

Comments
 (0)