Skip to content

Commit e0e148b

Browse files
[material_ui] Migrate M3 tabs template to use new gen_defaults (flutter#13139)
Work toward flutter#187899. Fixes flutter#188437 ## 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 9e9e3e9 commit e0e148b

6 files changed

Lines changed: 192 additions & 331 deletions

File tree

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/tabs_defaults.g.dart renamed to packages/material_ui/lib/src/generated/tabs_defaults_m3.g.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// Do not edit by hand. The code is generated from data in the Material
6+
// Design token database by the script:
7+
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
8+
part of '../tabs.dart';
9+
510
class _TabsPrimaryDefaultsM3 extends TabBarThemeData {
611
_TabsPrimaryDefaultsM3(this.context, this.isScrollable)
712
: super(indicatorSize: TabBarIndicatorSize.label);

‎packages/material_ui/lib/src/tabs.dart‎

Lines changed: 2 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import 'tab_indicator.dart';
2727
import 'text_theme.dart';
2828
import 'theme.dart';
2929

30+
part 'generated/tabs_defaults_m3.g.dart';
31+
3032
const double _kTabHeight = 46.0;
3133
const double _kTextAndIconTabHeight = 72.0;
3234
const double _kStartOffset = 52.0;
@@ -2853,162 +2855,3 @@ class _TabsDefaultsM2 extends TabBarThemeData {
28532855

28542856
static const EdgeInsetsGeometry iconMargin = EdgeInsets.only(bottom: 10);
28552857
}
2856-
2857-
// BEGIN GENERATED TOKEN PROPERTIES - Tabs
2858-
2859-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
2860-
// "END GENERATED" comments are generated from data in the Material
2861-
// Design token database by the script:
2862-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
2863-
2864-
// dart format off
2865-
class _TabsPrimaryDefaultsM3 extends TabBarThemeData {
2866-
_TabsPrimaryDefaultsM3(this.context, this.isScrollable)
2867-
: super(indicatorSize: TabBarIndicatorSize.label);
2868-
2869-
final BuildContext context;
2870-
late final ColorScheme _colors = Theme.of(context).colorScheme;
2871-
late final TextTheme _textTheme = Theme.of(context).textTheme;
2872-
final bool isScrollable;
2873-
2874-
// This value comes from Divider widget defaults. Token db deprecated 'primary-navigation-tab.divider.color' token.
2875-
@override
2876-
Color? get dividerColor => _colors.outlineVariant;
2877-
2878-
// This value comes from Divider widget defaults. Token db deprecated 'primary-navigation-tab.divider.height' token.
2879-
@override
2880-
double? get dividerHeight => 1.0;
2881-
2882-
@override
2883-
Color? get indicatorColor => _colors.primary;
2884-
2885-
@override
2886-
Color? get labelColor => _colors.primary;
2887-
2888-
@override
2889-
TextStyle? get labelStyle => _textTheme.titleSmall;
2890-
2891-
@override
2892-
Color? get unselectedLabelColor => _colors.onSurfaceVariant;
2893-
2894-
@override
2895-
TextStyle? get unselectedLabelStyle => _textTheme.titleSmall;
2896-
2897-
@override
2898-
WidgetStateProperty<Color?> get overlayColor {
2899-
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
2900-
if (states.contains(WidgetState.selected)) {
2901-
if (states.contains(WidgetState.pressed)) {
2902-
return _colors.primary.withOpacity(0.1);
2903-
}
2904-
if (states.contains(WidgetState.hovered)) {
2905-
return _colors.primary.withOpacity(0.08);
2906-
}
2907-
if (states.contains(WidgetState.focused)) {
2908-
return _colors.primary.withOpacity(0.1);
2909-
}
2910-
return null;
2911-
}
2912-
if (states.contains(WidgetState.pressed)) {
2913-
return _colors.primary.withOpacity(0.1);
2914-
}
2915-
if (states.contains(WidgetState.hovered)) {
2916-
return _colors.onSurface.withOpacity(0.08);
2917-
}
2918-
if (states.contains(WidgetState.focused)) {
2919-
return _colors.onSurface.withOpacity(0.1);
2920-
}
2921-
return null;
2922-
});
2923-
}
2924-
2925-
@override
2926-
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
2927-
2928-
@override
2929-
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill;
2930-
2931-
static double indicatorWeight(TabBarIndicatorSize indicatorSize) {
2932-
return switch (indicatorSize) {
2933-
TabBarIndicatorSize.label => 3.0,
2934-
TabBarIndicatorSize.tab => 2.0,
2935-
};
2936-
}
2937-
2938-
// TODO(davidmartos96): This value doesn't currently exist in
2939-
// https://m3.material.io/components/tabs/specs
2940-
// Update this when the token is available.
2941-
static const EdgeInsetsGeometry iconMargin = EdgeInsets.only(bottom: 2);
2942-
}
2943-
2944-
class _TabsSecondaryDefaultsM3 extends TabBarThemeData {
2945-
_TabsSecondaryDefaultsM3(this.context, this.isScrollable)
2946-
: super(indicatorSize: TabBarIndicatorSize.tab);
2947-
2948-
final BuildContext context;
2949-
late final ColorScheme _colors = Theme.of(context).colorScheme;
2950-
late final TextTheme _textTheme = Theme.of(context).textTheme;
2951-
final bool isScrollable;
2952-
2953-
// This value comes from Divider widget defaults. Token db deprecated 'secondary-navigation-tab.divider.color' token.
2954-
@override
2955-
Color? get dividerColor => _colors.outlineVariant;
2956-
2957-
// This value comes from Divider widget defaults. Token db deprecated 'secondary-navigation-tab.divider.height' token.
2958-
@override
2959-
double? get dividerHeight => 1.0;
2960-
2961-
@override
2962-
Color? get indicatorColor => _colors.primary;
2963-
2964-
@override
2965-
Color? get labelColor => _colors.onSurface;
2966-
2967-
@override
2968-
TextStyle? get labelStyle => _textTheme.titleSmall;
2969-
2970-
@override
2971-
Color? get unselectedLabelColor => _colors.onSurfaceVariant;
2972-
2973-
@override
2974-
TextStyle? get unselectedLabelStyle => _textTheme.titleSmall;
2975-
2976-
@override
2977-
WidgetStateProperty<Color?> get overlayColor {
2978-
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
2979-
if (states.contains(WidgetState.selected)) {
2980-
if (states.contains(WidgetState.pressed)) {
2981-
return _colors.onSurface.withOpacity(0.1);
2982-
}
2983-
if (states.contains(WidgetState.hovered)) {
2984-
return _colors.onSurface.withOpacity(0.08);
2985-
}
2986-
if (states.contains(WidgetState.focused)) {
2987-
return _colors.onSurface.withOpacity(0.1);
2988-
}
2989-
return null;
2990-
}
2991-
if (states.contains(WidgetState.pressed)) {
2992-
return _colors.onSurface.withOpacity(0.1);
2993-
}
2994-
if (states.contains(WidgetState.hovered)) {
2995-
return _colors.onSurface.withOpacity(0.08);
2996-
}
2997-
if (states.contains(WidgetState.focused)) {
2998-
return _colors.onSurface.withOpacity(0.1);
2999-
}
3000-
return null;
3001-
});
3002-
}
3003-
3004-
@override
3005-
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
3006-
3007-
@override
3008-
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill;
3009-
3010-
static double indicatorWeight = 2.0;
3011-
}
3012-
// dart format on
3013-
3014-
// END GENERATED TOKEN PROPERTIES - Tabs

‎packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ import '../templates/progress_indicator_template.dart';
5151
import '../templates/snackbar_template.dart';
5252
// import '../templates/surface_tint_template.dart';
5353
// import '../templates/switch_template.dart';
54-
// import '../templates/tabs_template.dart';
54+
import '../templates/tabs_template.dart';
55+
5556
// import '../templates/text_field_template.dart';
5657
// import '../templates/time_picker_template.dart';
5758
import '../templates/typography_template.dart';
@@ -113,7 +114,7 @@ Future<void> main(List<String> args) async {
113114
const SnackbarTemplateM3().generateFile(verbose: verbose);
114115
// const SurfaceTintTemplateM3().generateFile(verbose: verbose);
115116
// const SwitchTemplateM3().generateFile(verbose: verbose);
116-
// const TabsTemplateM3().generateFile(verbose: verbose);
117+
const TabsTemplateM3().generateFile(verbose: verbose);
117118
// const TextFieldTemplateM3().generateFile(verbose: verbose);
118119
// const TimePickerTemplateM3().generateFile(verbose: verbose);
119120
const TypographyTemplateM3().generateFile(verbose: verbose);
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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+
import '../data/divider.dart';
6+
import '../data/primary_navigation_tab.dart';
7+
import '../data/secondary_navigation_tab.dart';
8+
import 'template.dart';
9+
10+
class TabsTemplateM3 extends TokenTemplateM3 {
11+
const TabsTemplateM3();
12+
13+
@override
14+
String get name => 'Tabs';
15+
16+
@override
17+
String get parentFilePath => 'tabs.dart';
18+
19+
@override
20+
String get className => '';
21+
22+
@override
23+
String generateContents(String className) =>
24+
'''
25+
class _TabsPrimaryDefaultsM3 extends TabBarThemeData {
26+
_TabsPrimaryDefaultsM3(this.context, this.isScrollable)
27+
: super(indicatorSize: TabBarIndicatorSize.label);
28+
29+
final BuildContext context;
30+
late final ColorScheme _colors = Theme.of(context).colorScheme;
31+
late final TextTheme _textTheme = Theme.of(context).textTheme;
32+
final bool isScrollable;
33+
34+
// This value comes from Divider widget defaults. Token db deprecated 'primary-navigation-tab.divider.color' token.
35+
@override
36+
Color? get dividerColor => ${color(TokenDivider.color)};
37+
38+
// This value comes from Divider widget defaults. Token db deprecated 'primary-navigation-tab.divider.height' token.
39+
@override
40+
double? get dividerHeight => ${number(TokenDivider.thickness)};
41+
42+
@override
43+
Color? get indicatorColor => ${color(TokenPrimaryNavigationTab.activeIndicatorColor)};
44+
45+
@override
46+
Color? get labelColor => ${color(TokenPrimaryNavigationTab.withLabelTextActiveLabelTextColor)};
47+
48+
@override
49+
TextStyle? get labelStyle => ${textStyle(TokenPrimaryNavigationTab.withLabelTextLabelTextType, '_textTheme')};
50+
51+
@override
52+
Color? get unselectedLabelColor => ${color(TokenPrimaryNavigationTab.withLabelTextInactiveLabelTextColor)};
53+
54+
@override
55+
TextStyle? get unselectedLabelStyle => ${textStyle(TokenPrimaryNavigationTab.withLabelTextLabelTextType, '_textTheme')};
56+
57+
@override
58+
WidgetStateProperty<Color?> get overlayColor {
59+
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
60+
if (states.contains(WidgetState.selected)) {
61+
if (states.contains(WidgetState.pressed)) {
62+
return ${colorWithOpacity(TokenPrimaryNavigationTab.activePressedStateLayerColor, TokenPrimaryNavigationTab.activePressedStateLayerOpacity)};
63+
}
64+
if (states.contains(WidgetState.hovered)) {
65+
return ${colorWithOpacity(TokenPrimaryNavigationTab.activeHoverStateLayerColor, TokenPrimaryNavigationTab.activeHoverStateLayerOpacity)};
66+
}
67+
if (states.contains(WidgetState.focused)) {
68+
return ${colorWithOpacity(TokenPrimaryNavigationTab.activeFocusStateLayerColor, TokenPrimaryNavigationTab.activeFocusStateLayerOpacity)};
69+
}
70+
return null;
71+
}
72+
if (states.contains(WidgetState.pressed)) {
73+
return ${colorWithOpacity(TokenPrimaryNavigationTab.inactivePressedStateLayerColor, TokenPrimaryNavigationTab.inactivePressedStateLayerOpacity)};
74+
}
75+
if (states.contains(WidgetState.hovered)) {
76+
return ${colorWithOpacity(TokenPrimaryNavigationTab.inactiveHoverStateLayerColor, TokenPrimaryNavigationTab.inactiveHoverStateLayerOpacity)};
77+
}
78+
if (states.contains(WidgetState.focused)) {
79+
return ${colorWithOpacity(TokenPrimaryNavigationTab.inactiveFocusStateLayerColor, TokenPrimaryNavigationTab.inactiveFocusStateLayerOpacity)};
80+
}
81+
return null;
82+
});
83+
}
84+
85+
@override
86+
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
87+
88+
@override
89+
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill;
90+
91+
static double indicatorWeight(TabBarIndicatorSize indicatorSize) {
92+
return switch (indicatorSize) {
93+
TabBarIndicatorSize.label => ${number(TokenPrimaryNavigationTab.activeIndicatorHeight)},
94+
TabBarIndicatorSize.tab => ${number(TokenSecondaryNavigationTab.activeIndicatorHeight)},
95+
};
96+
}
97+
98+
// TODO(davidmartos96): This value doesn't currently exist in
99+
// https://m3.material.io/components/tabs/specs
100+
// Update this when the token is available.
101+
static const EdgeInsetsGeometry iconMargin = EdgeInsets.only(bottom: 2);
102+
}
103+
104+
class _TabsSecondaryDefaultsM3 extends TabBarThemeData {
105+
_TabsSecondaryDefaultsM3(this.context, this.isScrollable)
106+
: super(indicatorSize: TabBarIndicatorSize.tab);
107+
108+
final BuildContext context;
109+
late final ColorScheme _colors = Theme.of(context).colorScheme;
110+
late final TextTheme _textTheme = Theme.of(context).textTheme;
111+
final bool isScrollable;
112+
113+
// This value comes from Divider widget defaults. Token db deprecated 'secondary-navigation-tab.divider.color' token.
114+
@override
115+
Color? get dividerColor => ${color(TokenDivider.color)};
116+
117+
// This value comes from Divider widget defaults. Token db deprecated 'secondary-navigation-tab.divider.height' token.
118+
@override
119+
double? get dividerHeight => ${number(TokenDivider.thickness)};
120+
121+
@override
122+
Color? get indicatorColor => ${color(TokenSecondaryNavigationTab.activeIndicatorColor)};
123+
124+
@override
125+
Color? get labelColor => ${color(TokenSecondaryNavigationTab.activeLabelTextColor)};
126+
127+
@override
128+
TextStyle? get labelStyle => ${textStyle(TokenSecondaryNavigationTab.labelTextType, '_textTheme')};
129+
130+
@override
131+
Color? get unselectedLabelColor => ${color(TokenSecondaryNavigationTab.inactiveLabelTextColor)};
132+
133+
@override
134+
TextStyle? get unselectedLabelStyle => ${textStyle(TokenSecondaryNavigationTab.labelTextType, '_textTheme')};
135+
136+
@override
137+
WidgetStateProperty<Color?> get overlayColor {
138+
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
139+
if (states.contains(WidgetState.selected)) {
140+
if (states.contains(WidgetState.pressed)) {
141+
return ${colorWithOpacity(TokenSecondaryNavigationTab.pressedStateLayerColor, TokenSecondaryNavigationTab.pressedStateLayerOpacity)};
142+
}
143+
if (states.contains(WidgetState.hovered)) {
144+
return ${colorWithOpacity(TokenSecondaryNavigationTab.hoverStateLayerColor, TokenSecondaryNavigationTab.hoverStateLayerOpacity)};
145+
}
146+
if (states.contains(WidgetState.focused)) {
147+
return ${colorWithOpacity(TokenSecondaryNavigationTab.focusStateLayerColor, TokenSecondaryNavigationTab.focusStateLayerOpacity)};
148+
}
149+
return null;
150+
}
151+
if (states.contains(WidgetState.pressed)) {
152+
return ${colorWithOpacity(TokenSecondaryNavigationTab.pressedStateLayerColor, TokenSecondaryNavigationTab.pressedStateLayerOpacity)};
153+
}
154+
if (states.contains(WidgetState.hovered)) {
155+
return ${colorWithOpacity(TokenSecondaryNavigationTab.hoverStateLayerColor, TokenSecondaryNavigationTab.hoverStateLayerOpacity)};
156+
}
157+
if (states.contains(WidgetState.focused)) {
158+
return ${colorWithOpacity(TokenSecondaryNavigationTab.focusStateLayerColor, TokenSecondaryNavigationTab.focusStateLayerOpacity)};
159+
}
160+
return null;
161+
});
162+
}
163+
164+
@override
165+
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
166+
167+
@override
168+
TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill;
169+
170+
static double indicatorWeight = ${number(TokenSecondaryNavigationTab.activeIndicatorHeight)};
171+
}
172+
''';
173+
}

0 commit comments

Comments
 (0)