Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 2 additions & 42 deletions packages/material_ui/lib/src/bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import 'motion.dart';
import 'scaffold.dart';
import 'theme.dart';

part 'generated/bottom_sheet_defaults_m3.g.dart';

const Duration _kBottomSheetEnterDuration = Duration(milliseconds: 250);
const Duration _kBottomSheetExitDuration = Duration(milliseconds: 200);
const Curve _kModalBottomSheetCurve = Easing.legacyDecelerate;
Expand Down Expand Up @@ -1467,45 +1469,3 @@ class _BottomSheetGestureDetector extends StatelessWidget {
);
}
}

// BEGIN GENERATED TOKEN PROPERTIES - BottomSheet

// Do not edit by hand. The code between the "BEGIN GENERATED" and
// "END GENERATED" comments are generated from data in the Material
// Design token database by the script:
// dev/tools/gen_defaults/bin/gen_defaults.dart.

// dart format off
class _BottomSheetDefaultsM3 extends BottomSheetThemeData {
_BottomSheetDefaultsM3(this.context)
: super(
elevation: 1.0,
modalElevation: 1.0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(28.0))),
constraints: const BoxConstraints(maxWidth: 640),
);

final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;

@override
Color? get backgroundColor => _colors.surfaceContainerLow;

@override
Color? get surfaceTintColor => Colors.transparent;

@override
Color? get shadowColor => Colors.transparent;

@override
Color? get dragHandleColor => _colors.onSurfaceVariant;

@override
Size? get dragHandleSize => const Size(32, 4);

@override
BoxConstraints? get constraints => const BoxConstraints(maxWidth: 640.0);
}
// dart format on

// END GENERATED TOKEN PROPERTIES - BottomSheet
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Do not edit by hand. The code is generated from data in the Material
// Design token database by the script:
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
part of '../bottom_sheet.dart';

class _BottomSheetDefaultsM3 extends BottomSheetThemeData {
_BottomSheetDefaultsM3(this.context)
: super(
Expand Down Expand Up @@ -29,7 +34,7 @@ class _BottomSheetDefaultsM3 extends BottomSheetThemeData {
Color? get dragHandleColor => _colors.onSurfaceVariant;

@override
Size? get dragHandleSize => const Size(32, 4);
Size? get dragHandleSize => const Size(32.0, 4.0);

@override
BoxConstraints? get constraints => const BoxConstraints(maxWidth: 640.0);
Expand Down
2 changes: 2 additions & 0 deletions packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import 'package:args/args.dart';

import '../templates/app_bar_template.dart';
import '../templates/bottom_sheet_template.dart';

Future<void> main(List<String> args) async {
// Parse arguments
Expand All @@ -22,4 +23,5 @@ Future<void> main(List<String> args) async {
// TODO(elliette): Add token logger when verbose flag is used.
final verbose = argResults['verbose'] as bool;
const AppBarTemplateM3().generateFile(verbose: verbose);
const BottomSheetTemplateM3().generateFile(verbose: verbose);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../data/sheet_bottom.dart';
import 'template.dart';

class BottomSheetTemplateM3 extends TokenTemplateM3 {
const BottomSheetTemplateM3();

@override
String get name => 'Bottom Sheet';

@override
String get parentFilePath => 'bottom_sheet.dart';

@override
String generateContents(String className) =>
'''
class $className extends BottomSheetThemeData {
$className(this.context)
: super(
elevation: ${number(TokenSheetBottom.dockedStandardContainerElevation)},
modalElevation: ${number(TokenSheetBottom.dockedModalContainerElevation)},
shape: ${shape(TokenSheetBottom.dockedContainerShape)},
constraints: const BoxConstraints(maxWidth: 640),
);
Comment on lines +21 to +27

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the constraints getter on line 48, and to explicitly use double literals for BoxConstraints parameters, use 640.0 instead of 640.

Additionally, updating the constructor's indentation to match the standard Dart style guide (which is what dart format produces) makes the template code cleaner and easier to maintain.

Suggested change
$className(this.context)
: super(
elevation: ${number(TokenSheetBottom.dockedStandardContainerElevation)},
modalElevation: ${number(TokenSheetBottom.dockedModalContainerElevation)},
shape: ${shape(TokenSheetBottom.dockedContainerShape)},
constraints: const BoxConstraints(maxWidth: 640),
);
$className(this.context)
: super(
elevation: ${number(TokenSheetBottom.dockedStandardContainerElevation)},
modalElevation: ${number(TokenSheetBottom.dockedModalContainerElevation)},
shape: ${shape(TokenSheetBottom.dockedContainerShape)},
constraints: const BoxConstraints(maxWidth: 640.0),
);
References
  1. Code should follow the relevant style guides and use the correct auto-formatter (dart format for Dart). Aligning the template's formatting with the formatter's output ensures consistency and readability. (link)


final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;

@override
Color? get backgroundColor => ${color(TokenSheetBottom.dockedContainerColor, '_colors')};

@override
Color? get surfaceTintColor => Colors.transparent;

@override
Color? get shadowColor => Colors.transparent;

@override
Color? get dragHandleColor => ${color(TokenSheetBottom.dockedDragHandleColor, '_colors')};

@override
Size? get dragHandleSize => const Size(${number(TokenSheetBottom.dockedDragHandleWidth)}, ${number(TokenSheetBottom.dockedDragHandleHeight)});

@override
BoxConstraints? get constraints => const BoxConstraints(maxWidth: 640.0);
}
''';
}

This file was deleted.

20 changes: 20 additions & 0 deletions packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:test/test.dart';
import '../data/color_role.dart';
import '../data/shape_struct.dart';
import '../templates/app_bar_template.dart';
import '../templates/bottom_sheet_template.dart';
import '../templates/template.dart';
import 'test_fixtures/test_templates.dart';

Expand Down Expand Up @@ -159,6 +160,25 @@ void main() {
expect(contents, contains('static const double expandedHeight = 112.0'));
expect(contents, contains('static const double expandedHeight = 152.0'));
});

test('BottomSheetTemplateM3 emits M3 BottomSheet defaults from bottom sheet tokens', () {
final String contents = const BottomSheetTemplateM3().generateContents(
'_BottomSheetDefaultsM3',
);
expect(contents, contains('class _BottomSheetDefaultsM3 extends BottomSheetThemeData'));
expect(contents, contains('elevation: 1.0'));
expect(contents, contains('modalElevation: 1.0'));
expect(
contents,
contains(
'shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(28.0)))',
),
);
expect(contents, contains('Color? get backgroundColor => _colors.surfaceContainerLow'));
expect(contents, contains('Color? get dragHandleColor => _colors.onSurfaceVariant'));
expect(contents, contains('Size? get dragHandleSize => const Size(32.0, 4.0)'));
});

test('will run dart format over the generated file', () {
final template = UnformattedTemplate(testPath());
template.generateFile();
Expand Down