Skip to content

Commit 14a9b4a

Browse files
authored
Migrate AppBar to Material 3 (#101884)
1 parent 0c3c38d commit 14a9b4a

File tree

8 files changed

+554
-149
lines changed

8 files changed

+554
-149
lines changed

dev/tools/gen_defaults/bin/gen_defaults.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import 'dart:convert';
1818
import 'dart:io';
1919

20+
import 'package:gen_defaults/app_bar_template.dart';
2021
import 'package:gen_defaults/button_template.dart';
2122
import 'package:gen_defaults/card_template.dart';
2223
import 'package:gen_defaults/dialog_template.dart';
@@ -78,6 +79,7 @@ Future<void> main(List<String> args) async {
7879
tokens['colorsLight'] = _readTokenFile('color_light.json');
7980
tokens['colorsDark'] = _readTokenFile('color_dark.json');
8081

82+
AppBarTemplate('$materialLib/app_bar.dart', tokens).updateFile();
8183
ButtonTemplate('md.comp.elevated-button', '$materialLib/elevated_button.dart', tokens).updateFile();
8284
ButtonTemplate('md.comp.outlined-button', '$materialLib/outlined_button.dart', tokens).updateFile();
8385
ButtonTemplate('md.comp.text-button', '$materialLib/text_button.dart', tokens).updateFile();
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
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 'template.dart';
6+
7+
class AppBarTemplate extends TokenTemplate {
8+
const AppBarTemplate(super.fileName, super.tokens)
9+
: super(
10+
colorSchemePrefix: '_colors.',
11+
textThemePrefix: '_textTheme.',
12+
);
13+
14+
@override
15+
String generate() => '''
16+
// Generated version ${tokens["version"]}
17+
class _TokenDefaultsM3 extends AppBarTheme {
18+
_TokenDefaultsM3(this.context)
19+
: super(
20+
elevation: ${elevation('md.comp.top-app-bar.small.container')},
21+
scrolledUnderElevation: ${elevation('md.comp.top-app-bar.small.on-scroll.container')},
22+
titleSpacing: NavigationToolbar.kMiddleSpacing,
23+
toolbarHeight: ${tokens['md.comp.top-app-bar.small.container.height']},
24+
);
25+
26+
final BuildContext context;
27+
late final ThemeData _theme = Theme.of(context);
28+
late final ColorScheme _colors = _theme.colorScheme;
29+
late final TextTheme _textTheme = _theme.textTheme;
30+
31+
@override
32+
Color? get backgroundColor => ${componentColor('md.comp.top-app-bar.small.container')};
33+
34+
@override
35+
Color? get foregroundColor => ${color('md.comp.top-app-bar.small.headline.color')};
36+
37+
@override
38+
Color? get surfaceTintColor => ${componentColor('md.comp.top-app-bar.small.container.surface-tint-layer')};
39+
40+
@override
41+
IconThemeData? get iconTheme => IconThemeData(
42+
color: ${componentColor('md.comp.top-app-bar.small.leading-icon')},
43+
size: ${tokens['md.comp.top-app-bar.small.leading-icon.size']},
44+
);
45+
46+
@override
47+
IconThemeData? get actionsIconTheme => IconThemeData(
48+
color: ${componentColor('md.comp.top-app-bar.small.trailing-icon')},
49+
size: ${tokens['md.comp.top-app-bar.small.trailing-icon.size']},
50+
);
51+
52+
@override
53+
TextStyle? get toolbarTextStyle => _textTheme.bodyText2;
54+
55+
@override
56+
TextStyle? get titleTextStyle => ${textStyle('md.comp.top-app-bar.small.headline')};
57+
}''';
58+
}

0 commit comments

Comments
 (0)