Skip to content

Commit a7b0cf7

Browse files
elliettevictorsanni
authored andcommitted
[material_ui] Migrate M3 BottomSheet template to use new gen_defaults (flutter#12731)
Work towards flutter/flutter#191088 **Ports over flutter#12223 which landed on the `m3e_migration` feature branch.** ### Original PR description Work towards flutter/flutter#187899 Fixes flutter/flutter#188404 ## 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 fab4b95 commit a7b0cf7

6 files changed

Lines changed: 78 additions & 96 deletions

File tree

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

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import 'motion.dart';
2424
import 'scaffold.dart';
2525
import 'theme.dart';
2626

27+
part 'generated/bottom_sheet_defaults_m3.g.dart';
28+
2729
const Duration _kBottomSheetEnterDuration = Duration(milliseconds: 250);
2830
const Duration _kBottomSheetExitDuration = Duration(milliseconds: 200);
2931
const Curve _kModalBottomSheetCurve = Easing.legacyDecelerate;
@@ -1491,45 +1493,3 @@ class _BottomSheetGestureDetector extends StatelessWidget {
14911493
);
14921494
}
14931495
}
1494-
1495-
// BEGIN GENERATED TOKEN PROPERTIES - BottomSheet
1496-
1497-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
1498-
// "END GENERATED" comments are generated from data in the Material
1499-
// Design token database by the script:
1500-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
1501-
1502-
// dart format off
1503-
class _BottomSheetDefaultsM3 extends BottomSheetThemeData {
1504-
_BottomSheetDefaultsM3(this.context)
1505-
: super(
1506-
elevation: 1.0,
1507-
modalElevation: 1.0,
1508-
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(28.0))),
1509-
constraints: const BoxConstraints(maxWidth: 640),
1510-
);
1511-
1512-
final BuildContext context;
1513-
late final ColorScheme _colors = Theme.of(context).colorScheme;
1514-
1515-
@override
1516-
Color? get backgroundColor => _colors.surfaceContainerLow;
1517-
1518-
@override
1519-
Color? get surfaceTintColor => Colors.transparent;
1520-
1521-
@override
1522-
Color? get shadowColor => Colors.transparent;
1523-
1524-
@override
1525-
Color? get dragHandleColor => _colors.onSurfaceVariant;
1526-
1527-
@override
1528-
Size? get dragHandleSize => const Size(32, 4);
1529-
1530-
@override
1531-
BoxConstraints? get constraints => const BoxConstraints(maxWidth: 640.0);
1532-
}
1533-
// dart format on
1534-
1535-
// END GENERATED TOKEN PROPERTIES - BottomSheet

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/bottom_sheet_defaults.g.dart renamed to packages/material_ui/lib/src/generated/bottom_sheet_defaults_m3.g.dart

Lines changed: 6 additions & 1 deletion
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_sheet.dart';
9+
510
class _BottomSheetDefaultsM3 extends BottomSheetThemeData {
611
_BottomSheetDefaultsM3(this.context)
712
: super(
@@ -29,7 +34,7 @@ class _BottomSheetDefaultsM3 extends BottomSheetThemeData {
2934
Color? get dragHandleColor => _colors.onSurfaceVariant;
3035

3136
@override
32-
Size? get dragHandleSize => const Size(32, 4);
37+
Size? get dragHandleSize => const Size(32.0, 4.0);
3338

3439
@override
3540
BoxConstraints? get constraints => const BoxConstraints(maxWidth: 640.0);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import '../templates/app_bar_template.dart';
1818
// import '../templates/badge_template.dart';
1919
// import '../templates/banner_template.dart';
2020
// import '../templates/bottom_app_bar_template.dart';
21-
// import '../templates/bottom_sheet_template.dart';
21+
import '../templates/bottom_sheet_template.dart';
22+
2223
// import '../templates/button_template.dart';
2324
// import '../templates/card_template.dart';
2425
// import '../templates/checkbox_template.dart';
@@ -69,7 +70,7 @@ Future<void> main(List<String> args) async {
6970
// const BadgeTemplateM3().generateFile(verbose: verbose);
7071
// const BannerTemplateM3().generateFile(verbose: verbose);
7172
// const BottomAppBarTemplateM3().generateFile(verbose: verbose);
72-
// const BottomSheetTemplateM3().generateFile(verbose: verbose);
73+
const BottomSheetTemplateM3().generateFile(verbose: verbose);
7374
// const ButtonTemplateM3().generateFile(verbose: verbose);
7475
// const CardTemplateM3().generateFile(verbose: verbose);
7576
// const CheckboxTemplateM3().generateFile(verbose: verbose);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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/sheet_bottom.dart';
6+
import 'template.dart';
7+
8+
class BottomSheetTemplateM3 extends TokenTemplateM3 {
9+
const BottomSheetTemplateM3();
10+
11+
@override
12+
String get name => 'Bottom Sheet';
13+
14+
@override
15+
String get parentFilePath => 'bottom_sheet.dart';
16+
17+
@override
18+
String generateContents(String className) =>
19+
'''
20+
class $className extends BottomSheetThemeData {
21+
$className(this.context)
22+
: super(
23+
elevation: ${number(TokenSheetBottom.dockedStandardContainerElevation)},
24+
modalElevation: ${number(TokenSheetBottom.dockedModalContainerElevation)},
25+
shape: ${shape(TokenSheetBottom.dockedContainerShape)},
26+
constraints: const BoxConstraints(maxWidth: 640),
27+
);
28+
29+
final BuildContext context;
30+
late final ColorScheme _colors = Theme.of(context).colorScheme;
31+
32+
@override
33+
Color? get backgroundColor => ${color(TokenSheetBottom.dockedContainerColor, '_colors')};
34+
35+
@override
36+
Color? get surfaceTintColor => Colors.transparent;
37+
38+
@override
39+
Color? get shadowColor => Colors.transparent;
40+
41+
@override
42+
Color? get dragHandleColor => ${color(TokenSheetBottom.dockedDragHandleColor, '_colors')};
43+
44+
@override
45+
Size? get dragHandleSize => const Size(${number(TokenSheetBottom.dockedDragHandleWidth)}, ${number(TokenSheetBottom.dockedDragHandleHeight)});
46+
47+
@override
48+
BoxConstraints? get constraints => const BoxConstraints(maxWidth: 640.0);
49+
}
50+
''';
51+
}

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

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

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

Lines changed: 16 additions & 2 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/bottom_sheet_template.dart';
1415
import '../templates/template.dart';
1516
import 'test_fixtures/test_templates.dart';
1617

@@ -219,8 +220,21 @@ void main() {
219220
});
220221

221222
test('BottomSheetTemplateM3 emits M3 BottomSheet defaults from tokens', () {
222-
// Intentionally empty, will be implemented during migration. See:
223-
// https://github.com/flutter/flutter/issues/187899
223+
final String contents = const BottomSheetTemplateM3().generateContents(
224+
'_BottomSheetDefaultsM3',
225+
);
226+
expect(contents, contains('class _BottomSheetDefaultsM3 extends BottomSheetThemeData'));
227+
expect(contents, contains('elevation: 1.0'));
228+
expect(contents, contains('modalElevation: 1.0'));
229+
expect(
230+
contents,
231+
contains(
232+
'shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(28.0)))',
233+
),
234+
);
235+
expect(contents, contains('Color? get backgroundColor => _colors.surfaceContainerLow'));
236+
expect(contents, contains('Color? get dragHandleColor => _colors.onSurfaceVariant'));
237+
expect(contents, contains('Size? get dragHandleSize => const Size(32.0, 4.0)'));
224238
});
225239

226240
test('ButtonTemplateM3 emits M3 Button defaults from tokens', () {

0 commit comments

Comments
 (0)