Skip to content
Draft
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
35 changes: 2 additions & 33 deletions packages/material_ui/lib/src/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import 'badge_theme.dart';
import 'color_scheme.dart';
import 'theme.dart';

part 'generated/badge_defaults_m3.g.dart';

/// A Material Design "badge".
///
/// A badge's [label] conveys a small amount of information about its
Expand Down Expand Up @@ -476,36 +478,3 @@ class _RenderIntrinsicHorizontalStadium extends RenderProxyBox {
size = _computeSize(layoutChild: ChildLayoutHelper.layoutChild, constraints: constraints);
}
}

// BEGIN GENERATED TOKEN PROPERTIES - Badge

// 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 _BadgeDefaultsM3 extends BadgeThemeData {
_BadgeDefaultsM3(this.context) : super(
smallSize: 6.0,
largeSize: 16.0,
padding: const EdgeInsets.symmetric(horizontal: 4),
alignment: AlignmentDirectional.topEnd,
);

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

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

@override
Color? get textColor => _colors.onError;

@override
TextStyle? get textStyle => Theme.of(context).textTheme.labelSmall;
}
// dart format on

// END GENERATED TOKEN PROPERTIES - Badge
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 '../badge.dart';

class _BadgeDefaultsM3 extends BadgeThemeData {
_BadgeDefaultsM3(this.context)
: super(
Expand Down
5 changes: 3 additions & 2 deletions packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import 'package:args/args.dart';

// import '../templates/action_chip_template.dart';
import '../templates/app_bar_template.dart';
// import '../templates/badge_template.dart';
import '../templates/badge_template.dart';

// import '../templates/banner_template.dart';
// import '../templates/bottom_app_bar_template.dart';
// import '../templates/bottom_sheet_template.dart';
Expand Down Expand Up @@ -65,7 +66,7 @@ Future<void> main(List<String> args) async {

// const ActionChipTemplateM3().generateFile(verbose: verbose);
const AppBarTemplateM3().generateFile(verbose: verbose);
// const BadgeTemplateM3().generateFile(verbose: verbose);
const BadgeTemplateM3().generateFile(verbose: verbose);
// const BannerTemplateM3().generateFile(verbose: verbose);
// const BottomAppBarTemplateM3().generateFile(verbose: verbose);
// const BottomSheetTemplateM3().generateFile(verbose: verbose);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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/badge.dart';
import 'template.dart';

class BadgeTemplateM3 extends TokenTemplateM3 {
const BadgeTemplateM3();

@override
String get name => 'Badge';

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

@override
String generateContents(String className) =>
'''
class $className extends BadgeThemeData {
$className(this.context) : super(
smallSize: ${number(TokenBadge.size)},
largeSize: ${number(TokenBadge.largeSize)},
padding: const EdgeInsets.symmetric(horizontal: 4),
alignment: AlignmentDirectional.topEnd,
Comment thread
QuncCccccc marked this conversation as resolved.
);

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

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

@override
Color? get textColor => ${color(TokenBadge.largeLabelTextColor, '_colors')};

@override
TextStyle? get textStyle => Theme.of(context).textTheme.labelSmall;
}
''';
}

This file was deleted.

17 changes: 14 additions & 3 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/badge_template.dart';
import '../templates/template.dart';
import 'test_fixtures/test_templates.dart';

Expand Down Expand Up @@ -165,9 +166,19 @@ void main() {
expect(contents, contains('static const double expandedHeight = 152.0'));
});

test('BadgeTemplateM3 emits M3 Badge defaults from tokens', () {
// Intentionally empty, will be implemented during migration. See:
// https://github.com/flutter/flutter/issues/187899
test('BadgeTemplateM3 emits M3 Badge defaults from badge tokens', () {
final String contents = const BadgeTemplateM3().generateContents('_BadgeDefaultsM3');
expect(contents, contains('class _BadgeDefaultsM3 extends BadgeThemeData'));
expect(contents, contains('smallSize: 6.0'));
expect(contents, contains('largeSize: 16.0'));
expect(contents, contains('padding: const EdgeInsets.symmetric(horizontal: 4)'));
expect(contents, contains('alignment: AlignmentDirectional.topEnd'));
expect(contents, contains('Color? get backgroundColor => _colors.error'));
expect(contents, contains('Color? get textColor => _colors.onError'));
expect(
contents,
contains('TextStyle? get textStyle => Theme.of(context).textTheme.labelSmall'),
);
});

test('BannerTemplateM3 emits M3 Banner defaults from tokens', () {
Expand Down