Skip to content

Commit b7ec2d0

Browse files
authored
[material_ui] Migrate M3 BottomAppBar template to use new gen_defaults (flutter#13385)
Work toward flutter#187899 Fixes flutter#188403 This PR migrates the M3 BottomAppBar defaults template to use the new gen_defaults in material_ui. ## Pre-Review Checklist **Changelog/version exemption:** No-op, pure migration. **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 108dad0 commit b7ec2d0

6 files changed

Lines changed: 64 additions & 76 deletions

File tree

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import 'material.dart';
2020
import 'scaffold.dart';
2121
import 'theme.dart';
2222

23+
part 'generated/bottom_app_bar_defaults_m3.g.dart';
24+
2325
// Examples can assume:
2426
// late Widget bottomAppBarContents;
2527

@@ -309,35 +311,3 @@ class _BottomAppBarDefaultsM2 extends BottomAppBarThemeData {
309311
@override
310312
Color get shadowColor => const Color(0xFF000000);
311313
}
312-
313-
// BEGIN GENERATED TOKEN PROPERTIES - BottomAppBar
314-
315-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
316-
// "END GENERATED" comments are generated from data in the Material
317-
// Design token database by the script:
318-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
319-
320-
// dart format off
321-
class _BottomAppBarDefaultsM3 extends BottomAppBarThemeData {
322-
_BottomAppBarDefaultsM3(this.context)
323-
: super(
324-
elevation: 3.0,
325-
height: 80.0,
326-
shape: const AutomaticNotchedShape(RoundedRectangleBorder()),
327-
);
328-
329-
final BuildContext context;
330-
late final ColorScheme _colors = Theme.of(context).colorScheme;
331-
332-
@override
333-
Color? get color => _colors.surfaceContainer;
334-
335-
@override
336-
Color? get surfaceTintColor => Colors.transparent;
337-
338-
@override
339-
Color? get shadowColor => Colors.transparent;
340-
}
341-
// dart format on
342-
343-
// END GENERATED TOKEN PROPERTIES - BottomAppBar

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/bottom_app_bar_defaults.g.dart renamed to packages/material_ui/lib/src/generated/bottom_app_bar_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 '../bottom_app_bar.dart';
9+
510
class _BottomAppBarDefaultsM3 extends BottomAppBarThemeData {
611
_BottomAppBarDefaultsM3(this.context)
712
: super(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import '../templates/action_chip_template.dart';
1616
import '../templates/app_bar_template.dart';
1717
import '../templates/badge_template.dart';
1818
import '../templates/banner_template.dart';
19-
// import '../templates/bottom_app_bar_template.dart';
19+
import '../templates/bottom_app_bar_template.dart';
2020
import '../templates/bottom_sheet_template.dart';
2121
import '../templates/button_template.dart';
2222
import '../templates/card_template.dart';
@@ -69,7 +69,7 @@ Future<void> main(List<String> args) async {
6969
const AppBarTemplateM3().generateFile(verbose: verbose);
7070
const BadgeTemplateM3().generateFile(verbose: verbose);
7171
const BannerTemplateM3().generateFile(verbose: verbose);
72-
// const BottomAppBarTemplateM3().generateFile(verbose: verbose);
72+
const BottomAppBarTemplateM3().generateFile(verbose: verbose);
7373
const BottomSheetTemplateM3().generateFile(verbose: verbose);
7474
const ButtonTemplateM3('Elevated Button').generateFile(verbose: verbose);
7575
const ButtonTemplateM3('Filled Button').generateFile(verbose: verbose);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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/bottom_app_bar.dart';
6+
import 'template.dart';
7+
8+
class BottomAppBarTemplateM3 extends TokenTemplateM3 {
9+
const BottomAppBarTemplateM3();
10+
11+
@override
12+
String get name => 'Bottom App Bar';
13+
14+
@override
15+
String get parentFilePath => 'bottom_app_bar.dart';
16+
17+
// TODO(elliette): Replace with a token when/if it becomes available.
18+
static const String _surfaceTintColor = 'Colors.transparent';
19+
20+
@override
21+
String generateContents(String className) =>
22+
'''
23+
class $className extends BottomAppBarThemeData {
24+
$className(this.context)
25+
: super(
26+
elevation: ${number(TokenBottomAppBar.containerElevation)},
27+
height: ${number(TokenBottomAppBar.containerHeight)},
28+
shape: const AutomaticNotchedShape(${shape(TokenBottomAppBar.containerShape, '')}),
29+
);
30+
31+
final BuildContext context;
32+
late final ColorScheme _colors = Theme.of(context).colorScheme;
33+
34+
@override
35+
Color? get color => ${color(TokenBottomAppBar.containerColor)};
36+
37+
@override
38+
Color? get surfaceTintColor => $_surfaceTintColor;
39+
40+
@override
41+
Color? get shadowColor => Colors.transparent;
42+
}
43+
''';
44+
}

‎packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/bottom_app_bar_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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import '../templates/action_chip_template.dart';
1414
import '../templates/app_bar_template.dart';
1515
import '../templates/badge_template.dart';
1616
import '../templates/banner_template.dart';
17-
// import '../templates/bottom_app_bar_template.dart';
17+
import '../templates/bottom_app_bar_template.dart';
1818
import '../templates/bottom_sheet_template.dart';
1919
import '../templates/button_template.dart';
2020
import '../templates/card_template.dart';
@@ -298,8 +298,16 @@ void main() {
298298
});
299299

300300
test('BottomAppBarTemplateM3 emits M3 BottomAppBar defaults from tokens', () {
301-
// Intentionally empty, will be implemented during migration. See:
302-
// https://github.com/flutter/flutter/issues/187899
301+
final String contents = const BottomAppBarTemplateM3().generateContents(
302+
'_BottomAppBarDefaultsM3',
303+
);
304+
expect(contents, contains('class _BottomAppBarDefaultsM3 extends BottomAppBarThemeData'));
305+
expect(contents, contains('elevation: 3.0'));
306+
expect(contents, contains('height: 80.0'));
307+
expect(contents, contains('shape: const AutomaticNotchedShape(RoundedRectangleBorder())'));
308+
expect(contents, contains('Color? get color => _colors.surfaceContainer'));
309+
expect(contents, contains('Color? get surfaceTintColor => Colors.transparent'));
310+
expect(contents, contains('Color? get shadowColor => Colors.transparent'));
303311
});
304312

305313
test('BottomSheetTemplateM3 emits M3 BottomSheet defaults from tokens', () {

0 commit comments

Comments
 (0)