Skip to content

Commit 0308729

Browse files
authored
[material_ui] Migrate M3 Banner template to use new gen_defaults (#12227)
Work towards flutter/flutter#187899 Fixes flutter/flutter#188402 ## Pre-Review Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran [the auto-formatter]. - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1]. - [x] I updated/added any relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1]. - [x] All existing and new tests are passing.
1 parent b189c7e commit 0308729

6 files changed

Lines changed: 60 additions & 76 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

@@ -489,35 +491,3 @@ class _BannerDefaultsM2 extends MaterialBannerThemeData {
489491
@override
490492
TextStyle? get contentTextStyle => _theme.textTheme.bodyMedium;
491493
}
492-
493-
// BEGIN GENERATED TOKEN PROPERTIES - Banner
494-
495-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
496-
// "END GENERATED" comments are generated from data in the Material
497-
// Design token database by the script:
498-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
499-
500-
// dart format off
501-
class _BannerDefaultsM3 extends MaterialBannerThemeData {
502-
_BannerDefaultsM3(this.context)
503-
: super(elevation: 1.0);
504-
505-
final BuildContext context;
506-
late final ColorScheme _colors = Theme.of(context).colorScheme;
507-
late final TextTheme _textTheme = Theme.of(context).textTheme;
508-
509-
@override
510-
Color? get backgroundColor => _colors.surfaceContainerLow;
511-
512-
@override
513-
Color? get surfaceTintColor => Colors.transparent;
514-
515-
@override
516-
Color? get dividerColor => _colors.outlineVariant;
517-
518-
@override
519-
TextStyle? get contentTextStyle => _textTheme.bodyMedium;
520-
}
521-
// dart format on
522-
523-
// 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
@@ -14,8 +14,8 @@ import 'package:args/args.dart';
1414

1515
import '../templates/action_chip_template.dart';
1616
import '../templates/app_bar_template.dart';
17+
import '../templates/banner_template.dart';
1718
import '../templates/badge_template.dart';
18-
// import '../templates/banner_template.dart';
1919
// import '../templates/bottom_app_bar_template.dart';
2020
import '../templates/bottom_sheet_template.dart';
2121
// import '../templates/button_template.dart';
@@ -65,8 +65,8 @@ Future<void> main(List<String> args) async {
6565

6666
const ActionChipTemplateM3().generateFile(verbose: verbose);
6767
const AppBarTemplateM3().generateFile(verbose: verbose);
68+
const BannerTemplateM3().generateFile(verbose: verbose);
6869
const BadgeTemplateM3().generateFile(verbose: verbose);
69-
// const BannerTemplateM3().generateFile(verbose: verbose);
7070
// const BottomAppBarTemplateM3().generateFile(verbose: verbose);
7171
const BottomSheetTemplateM3().generateFile(verbose: verbose);
7272
// 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 & 39 deletions
This file was deleted.

‎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
@@ -11,6 +11,7 @@ import '../data/typescale.dart';
1111
import '../data/typescale_emphasized.dart';
1212
import '../templates/action_chip_template.dart';
1313
import '../templates/app_bar_template.dart';
14+
import '../templates/banner_template.dart';
1415
import '../templates/badge_template.dart';
1516
import '../templates/bottom_sheet_template.dart';
1617
import '../templates/template.dart';
@@ -220,9 +221,14 @@ void main() {
220221
);
221222
});
222223

223-
test('BannerTemplateM3 emits M3 Banner defaults from tokens', () {
224-
// Intentionally empty, will be implemented during migration. See:
225-
// https://github.com/flutter/flutter/issues/187899
224+
test('BannerTemplateM3 emits M3 Banner defaults from banner tokens', () {
225+
final String contents = _generateContents(const BannerTemplateM3());
226+
expect(contents, contains('class _BannerDefaultsM3 extends MaterialBannerThemeData'));
227+
expect(contents, contains('elevation: 1.0'));
228+
expect(contents, contains('Color? get backgroundColor => _colors.surfaceContainerLow'));
229+
expect(contents, contains('Color? get surfaceTintColor => Colors.transparent'));
230+
expect(contents, contains('Color? get dividerColor => _colors.outlineVariant'));
231+
expect(contents, contains('TextStyle? get contentTextStyle => _textTheme.bodyMedium'));
226232
});
227233

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

0 commit comments

Comments
 (0)