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
34 changes: 2 additions & 32 deletions packages/material_ui/lib/src/banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import 'scaffold.dart';
import 'text_theme.dart';
import 'theme.dart';

part 'generated/banner_defaults_m3.g.dart';

// Examples can assume:
// late BuildContext context;

Expand Down Expand Up @@ -489,35 +491,3 @@ class _BannerDefaultsM2 extends MaterialBannerThemeData {
@override
TextStyle? get contentTextStyle => _theme.textTheme.bodyMedium;
}

// BEGIN GENERATED TOKEN PROPERTIES - Banner

// 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 _BannerDefaultsM3 extends MaterialBannerThemeData {
_BannerDefaultsM3(this.context)
: super(elevation: 1.0);

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

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

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

@override
Color? get dividerColor => _colors.outlineVariant;

@override
TextStyle? get contentTextStyle => _textTheme.bodyMedium;
}
// dart format on

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

class _BannerDefaultsM3 extends MaterialBannerThemeData {
_BannerDefaultsM3(this.context) : super(elevation: 1.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/banner_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 BannerTemplateM3().generateFile(verbose: verbose);
}
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/banner.dart';
import '../data/divider.dart';
import 'template.dart';

class BannerTemplateM3 extends TokenTemplateM3 {
const BannerTemplateM3();

@override
String get name => 'Banner';

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

@override
String generateContents(String className) =>
'''
class $className extends MaterialBannerThemeData {
$className(this.context)
: super(elevation: ${number(TokenBanner.containerElevation)});

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

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

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

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

@override
TextStyle? get contentTextStyle => _textTheme.bodyMedium;
}
''';
}

This file was deleted.

12 changes: 12 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/banner_template.dart';
import '../templates/template.dart';
import 'test_fixtures/test_templates.dart';

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

test('BannerTemplateM3 emits M3 Banner defaults from banner tokens', () {
final String contents = const BannerTemplateM3().generateContents('_BannerDefaultsM3');
expect(contents, contains('class _BannerDefaultsM3 extends MaterialBannerThemeData'));
expect(contents, contains('elevation: 1.0'));
expect(contents, contains('Color? get backgroundColor => _colors.surfaceContainerLow'));
expect(contents, contains('Color? get surfaceTintColor => Colors.transparent'));
expect(contents, contains('Color? get dividerColor => _colors.outlineVariant'));
expect(contents, contains('TextStyle? get contentTextStyle => _textTheme.bodyMedium'));
});

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