Skip to content

Commit cd4cdd0

Browse files
authored
[material_ui] Add all M3 templates and generated code to temporarily_excluded/ before migration (#12661)
Work towards flutter/flutter#191088 **Ports over #12206 which landed on the `m3e_migration` feature branch.** ### Original PR description Work towards flutter/flutter#187899 Moves all M3 templates and their generated code to gen_defaults/temporarily_excluded before we begin migrating. This way when we migrate each component, we can first move the template and its respective generated code into the new directories, edit the template, and re-generate the code. This will make it easier to review changes to the templates and validate the generated output. ## 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 0bab416 commit cd4cdd0

96 files changed

Lines changed: 10063 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
include: ../../../../analysis_options.yaml
22

3-
formatter:
4-
page_width: 100
53
analyzer:
64
exclude:
5+
# TODO(elliette): Remove the following exclusion once all M3 templates
6+
# have been migrated. See https://github.com/flutter/flutter/issues/187899.
7+
- temporarily_excluded/**
78
- build/**
89
- android/**
910
- ios/**
1011
- web/**
1112
- windows/**
1213
- macos/**
1314
- linux/**
15+
16+
formatter:
17+
page_width: 100
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
class _ActionChipDefaultsM3 extends ChipThemeData {
6+
_ActionChipDefaultsM3(this.context, this.isEnabled, this._chipVariant)
7+
: super(
8+
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
9+
showCheckmark: true,
10+
);
11+
12+
final BuildContext context;
13+
final bool isEnabled;
14+
final _ChipVariant _chipVariant;
15+
late final ColorScheme _colors = Theme.of(context).colorScheme;
16+
late final TextTheme _textTheme = Theme.of(context).textTheme;
17+
18+
@override
19+
double? get elevation => _chipVariant == _ChipVariant.flat
20+
? 0.0
21+
: isEnabled
22+
? 1.0
23+
: 0.0;
24+
25+
@override
26+
double? get pressElevation => 1.0;
27+
28+
@override
29+
TextStyle? get labelStyle =>
30+
_textTheme.labelLarge?.copyWith(color: isEnabled ? _colors.onSurface : _colors.onSurface);
31+
32+
@override
33+
WidgetStateProperty<Color?>? get color =>
34+
WidgetStateProperty.resolveWith((Set<WidgetState> states) {
35+
if (states.contains(WidgetState.disabled)) {
36+
return _chipVariant == _ChipVariant.flat ? null : _colors.onSurface.withOpacity(0.12);
37+
}
38+
return _chipVariant == _ChipVariant.flat ? null : _colors.surfaceContainerLow;
39+
});
40+
41+
@override
42+
Color? get shadowColor => _chipVariant == _ChipVariant.flat ? Colors.transparent : _colors.shadow;
43+
44+
@override
45+
Color? get surfaceTintColor => Colors.transparent;
46+
47+
@override
48+
Color? get checkmarkColor => null;
49+
50+
@override
51+
Color? get deleteIconColor => null;
52+
53+
@override
54+
BorderSide? get side => _chipVariant == _ChipVariant.flat
55+
? isEnabled
56+
? BorderSide(color: _colors.outlineVariant)
57+
: BorderSide(color: _colors.onSurface.withOpacity(0.12))
58+
: const BorderSide(color: Colors.transparent);
59+
60+
@override
61+
IconThemeData? get iconTheme =>
62+
IconThemeData(color: isEnabled ? _colors.primary : _colors.onSurface, size: 18.0);
63+
64+
@override
65+
EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0);
66+
67+
/// The label padding of the chip scales with the font size specified in the
68+
/// [labelStyle], and the system font size settings that scale font sizes
69+
/// globally.
70+
///
71+
/// The chip at effective font size 14.0 starts with 8px on each side and as
72+
/// the font size scales up to closer to 28.0, the label padding is linearly
73+
/// interpolated from 8px to 4px. Once the label has a font size of 2 or
74+
/// higher, label padding remains 4px.
75+
@override
76+
EdgeInsetsGeometry? get labelPadding {
77+
final double fontSize = labelStyle?.fontSize ?? 14.0;
78+
final double fontSizeRatio = MediaQuery.textScalerOf(context).scale(fontSize) / 14.0;
79+
return EdgeInsets.lerp(
80+
const EdgeInsets.symmetric(horizontal: 8.0),
81+
const EdgeInsets.symmetric(horizontal: 4.0),
82+
clampDouble(fontSizeRatio - 1.0, 0.0, 1.0),
83+
)!;
84+
}
85+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
class _AppBarDefaultsM3 extends AppBarThemeData {
6+
_AppBarDefaultsM3(this.context)
7+
: super(
8+
elevation: 0.0,
9+
scrolledUnderElevation: 3.0,
10+
titleSpacing: NavigationToolbar.kMiddleSpacing,
11+
toolbarHeight: 64.0,
12+
);
13+
14+
final BuildContext context;
15+
late final ThemeData _theme = Theme.of(context);
16+
late final ColorScheme _colors = _theme.colorScheme;
17+
late final TextTheme _textTheme = _theme.textTheme;
18+
19+
@override
20+
Color? get backgroundColor => _colors.surface;
21+
22+
@override
23+
Color? get foregroundColor => _colors.onSurface;
24+
25+
@override
26+
Color? get shadowColor => Colors.transparent;
27+
28+
@override
29+
Color? get surfaceTintColor => Colors.transparent;
30+
31+
@override
32+
IconThemeData? get iconTheme => IconThemeData(color: _colors.onSurface, size: 24.0);
33+
34+
@override
35+
IconThemeData? get actionsIconTheme => IconThemeData(color: _colors.onSurfaceVariant, size: 24.0);
36+
37+
@override
38+
TextStyle? get toolbarTextStyle => _textTheme.bodyMedium;
39+
40+
@override
41+
TextStyle? get titleTextStyle => _textTheme.titleLarge;
42+
43+
// TODO(Craftplacer): Consider using EdgeInsets.only(right: 8.0) instead of
44+
// EdgeInsets.zero for Material 3 in the future,
45+
// https://github.com/flutter/flutter/issues/155747
46+
@override
47+
EdgeInsets? get actionsPadding => EdgeInsets.zero;
48+
}
49+
50+
// Variant configuration
51+
class _MediumScrollUnderFlexibleConfig with _ScrollUnderFlexibleConfig {
52+
_MediumScrollUnderFlexibleConfig(this.context);
53+
54+
final BuildContext context;
55+
late final ThemeData _theme = Theme.of(context);
56+
late final ColorScheme _colors = _theme.colorScheme;
57+
late final TextTheme _textTheme = _theme.textTheme;
58+
59+
static const double collapsedHeight = 64.0;
60+
static const double expandedHeight = 112.0;
61+
62+
@override
63+
TextStyle? get collapsedTextStyle => _textTheme.titleLarge?.apply(color: _colors.onSurface);
64+
65+
@override
66+
TextStyle? get expandedTextStyle => _textTheme.headlineSmall?.apply(color: _colors.onSurface);
67+
68+
@override
69+
EdgeInsetsGeometry get expandedTitlePadding => const EdgeInsets.fromLTRB(16, 0, 16, 20);
70+
}
71+
72+
class _LargeScrollUnderFlexibleConfig with _ScrollUnderFlexibleConfig {
73+
_LargeScrollUnderFlexibleConfig(this.context);
74+
75+
final BuildContext context;
76+
late final ThemeData _theme = Theme.of(context);
77+
late final ColorScheme _colors = _theme.colorScheme;
78+
late final TextTheme _textTheme = _theme.textTheme;
79+
80+
static const double collapsedHeight = 64.0;
81+
static const double expandedHeight = 152.0;
82+
83+
@override
84+
TextStyle? get collapsedTextStyle => _textTheme.titleLarge?.apply(color: _colors.onSurface);
85+
86+
@override
87+
TextStyle? get expandedTextStyle => _textTheme.headlineMedium?.apply(color: _colors.onSurface);
88+
89+
@override
90+
EdgeInsetsGeometry get expandedTitlePadding => const EdgeInsets.fromLTRB(16, 0, 16, 28);
91+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
class _BadgeDefaultsM3 extends BadgeThemeData {
6+
_BadgeDefaultsM3(this.context)
7+
: super(
8+
smallSize: 6.0,
9+
largeSize: 16.0,
10+
padding: const EdgeInsets.symmetric(horizontal: 4),
11+
alignment: AlignmentDirectional.topEnd,
12+
);
13+
14+
final BuildContext context;
15+
late final ThemeData _theme = Theme.of(context);
16+
late final ColorScheme _colors = _theme.colorScheme;
17+
18+
@override
19+
Color? get backgroundColor => _colors.error;
20+
21+
@override
22+
Color? get textColor => _colors.onError;
23+
24+
@override
25+
TextStyle? get textStyle => Theme.of(context).textTheme.labelSmall;
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
class _BannerDefaultsM3 extends MaterialBannerThemeData {
6+
_BannerDefaultsM3(this.context) : super(elevation: 1.0);
7+
8+
final BuildContext context;
9+
late final ColorScheme _colors = Theme.of(context).colorScheme;
10+
late final TextTheme _textTheme = Theme.of(context).textTheme;
11+
12+
@override
13+
Color? get backgroundColor => _colors.surfaceContainerLow;
14+
15+
@override
16+
Color? get surfaceTintColor => Colors.transparent;
17+
18+
@override
19+
Color? get dividerColor => _colors.outlineVariant;
20+
21+
@override
22+
TextStyle? get contentTextStyle => _textTheme.bodyMedium;
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
class _BottomAppBarDefaultsM3 extends BottomAppBarThemeData {
6+
_BottomAppBarDefaultsM3(this.context)
7+
: super(
8+
elevation: 3.0,
9+
height: 80.0,
10+
shape: const AutomaticNotchedShape(RoundedRectangleBorder()),
11+
);
12+
13+
final BuildContext context;
14+
late final ColorScheme _colors = Theme.of(context).colorScheme;
15+
16+
@override
17+
Color? get color => _colors.surfaceContainer;
18+
19+
@override
20+
Color? get surfaceTintColor => Colors.transparent;
21+
22+
@override
23+
Color? get shadowColor => Colors.transparent;
24+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
class _BottomSheetDefaultsM3 extends BottomSheetThemeData {
6+
_BottomSheetDefaultsM3(this.context)
7+
: super(
8+
elevation: 1.0,
9+
modalElevation: 1.0,
10+
shape: const RoundedRectangleBorder(
11+
borderRadius: BorderRadius.vertical(top: Radius.circular(28.0)),
12+
),
13+
constraints: const BoxConstraints(maxWidth: 640),
14+
);
15+
16+
final BuildContext context;
17+
late final ColorScheme _colors = Theme.of(context).colorScheme;
18+
19+
@override
20+
Color? get backgroundColor => _colors.surfaceContainerLow;
21+
22+
@override
23+
Color? get surfaceTintColor => Colors.transparent;
24+
25+
@override
26+
Color? get shadowColor => Colors.transparent;
27+
28+
@override
29+
Color? get dragHandleColor => _colors.onSurfaceVariant;
30+
31+
@override
32+
Size? get dragHandleSize => const Size(32, 4);
33+
34+
@override
35+
BoxConstraints? get constraints => const BoxConstraints(maxWidth: 640.0);
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
class _CardDefaultsM3 extends CardThemeData {
6+
_CardDefaultsM3(this.context)
7+
: super(clipBehavior: Clip.none, elevation: 1.0, margin: const EdgeInsets.all(4.0));
8+
9+
final BuildContext context;
10+
late final ColorScheme _colors = Theme.of(context).colorScheme;
11+
12+
@override
13+
Color? get color => _colors.surfaceContainerLow;
14+
15+
@override
16+
Color? get shadowColor => _colors.shadow;
17+
18+
@override
19+
Color? get surfaceTintColor => Colors.transparent;
20+
21+
@override
22+
ShapeBorder? get shape =>
23+
const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0)));
24+
}

0 commit comments

Comments
 (0)