Skip to content

Commit 2532584

Browse files
authored
Update parameters to the styleFrom button methods. (#105291)
* Update parameters to the `styleFrom` button methods. * Updated the Flutter fix data to point to this PR. * Updated handling of background color to better maintain backwards compatibility with previous API.
1 parent ce10e6f commit 2532584

File tree

21 files changed

+404
-106
lines changed

21 files changed

+404
-106
lines changed

dev/integration_tests/flutter_gallery/lib/demo/material/cards_demo.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class TravelDestinationContent extends StatelessWidget {
247247
final ThemeData theme = Theme.of(context);
248248
final TextStyle titleStyle = theme.textTheme.headline5!.copyWith(color: Colors.white);
249249
final TextStyle descriptionStyle = theme.textTheme.subtitle1!;
250-
final ButtonStyle textButtonStyle = TextButton.styleFrom(primary: Colors.amber.shade500);
250+
final ButtonStyle textButtonStyle = TextButton.styleFrom(foregroundColor: Colors.amber.shade500);
251251

252252
return Column(
253253
crossAxisAlignment: CrossAxisAlignment.start,

dev/integration_tests/flutter_gallery/lib/demo/shrine/shopping_cart.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class _ShoppingCartPageState extends State<ShoppingCartPage> {
7878
right: 16.0,
7979
child: ElevatedButton(
8080
style: ElevatedButton.styleFrom(
81-
primary: kShrinePink100,
81+
backgroundColor: kShrinePink100,
8282
shape: const BeveledRectangleBorder(
8383
borderRadius: BorderRadius.all(Radius.circular(7.0)),
8484
),

dev/integration_tests/flutter_gallery/lib/gallery/options.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class _TextButton extends StatelessWidget {
177177
final ThemeData theme = Theme.of(context);
178178
return TextButton(
179179
style: TextButton.styleFrom(
180-
primary: theme.colorScheme.onPrimary,
180+
foregroundColor: theme.colorScheme.onPrimary,
181181
textStyle: theme.textTheme.subtitle1,
182182
padding: EdgeInsets.zero,
183183
),

dev/manual_tests/lib/density.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ class _MyHomePageState extends State<MyHomePage> {
534534
label: _model.rtl ? 'زر مسطح' : 'Text Button',
535535
child: TextButton(
536536
style: TextButton.styleFrom(
537-
primary: Colors.white,
537+
foregroundColor: Colors.white,
538538
backgroundColor: m2Swatch[200]
539539
),
540540
onPressed: _model.enable ? () {} : null,

dev/manual_tests/lib/text.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,47 @@ class _HomeState extends State<Home> {
4444
children: <Widget>[
4545
TextButton(
4646
style: TextButton.styleFrom(
47-
primary: Colors.white,
47+
foregroundColor: Colors.white,
4848
backgroundColor: Colors.red.shade800,
4949
),
5050
onPressed: () { Navigator.pushNamed(context, 'underlines'); },
5151
child: const Text('Test Underlines'),
5252
),
5353
TextButton(
5454
style: TextButton.styleFrom(
55-
primary: Colors.white,
55+
foregroundColor: Colors.white,
5656
backgroundColor: Colors.orange.shade700,
5757
),
5858
onPressed: () { Navigator.pushNamed(context, 'fallback'); },
5959
child: const Text('Test Font Fallback'),
6060
),
6161
TextButton(
6262
style: TextButton.styleFrom(
63-
primary: Colors.black,
63+
foregroundColor: Colors.black,
6464
backgroundColor: Colors.yellow.shade700,
6565
),
6666
onPressed: () { Navigator.pushNamed(context, 'bidi'); },
6767
child: const Text('Test Bidi Formatting'),
6868
),
6969
TextButton(
7070
style: TextButton.styleFrom(
71-
primary: Colors.black,
71+
foregroundColor: Colors.black,
7272
backgroundColor: Colors.green.shade400,
7373
),
7474
onPressed: () { Navigator.pushNamed(context, 'fuzzer'); },
7575
child: const Text('TextSpan Fuzzer'),
7676
),
7777
TextButton(
7878
style: TextButton.styleFrom(
79-
primary: Colors.white,
79+
foregroundColor: Colors.white,
8080
backgroundColor: Colors.blue.shade400,
8181
),
8282
onPressed: () { Navigator.pushNamed(context, 'zalgo'); },
8383
child: const Text('Diacritics Fuzzer'),
8484
),
8585
TextButton(
8686
style: TextButton.styleFrom(
87-
primary: Colors.black,
87+
foregroundColor: Colors.black,
8888
backgroundColor: Colors.purple.shade200,
8989
),
9090
onPressed: () { Navigator.pushNamed(context, 'painting'); },
@@ -618,7 +618,7 @@ class _UnderlinesState extends State<Underlines> {
618618
),
619619
TextButton(
620620
style: TextButton.styleFrom(
621-
primary: Colors.white,
621+
foregroundColor: Colors.white,
622622
backgroundColor: Colors.red,
623623
),
624624
onPressed: _text == '' ? null : () {

examples/api/lib/material/app_bar/app_bar.2.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AppBarExample extends StatelessWidget {
2525
@override
2626
Widget build(BuildContext context) {
2727
final ButtonStyle style = TextButton.styleFrom(
28-
primary: Theme.of(context).colorScheme.onPrimary,
28+
foregroundColor: Theme.of(context).colorScheme.onPrimary,
2929
);
3030
return Scaffold(
3131
appBar: AppBar(

examples/api/lib/material/button_style/button_style.0.dart

+4-8
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ class ButtonTypesGroup extends StatelessWidget {
6363
// 'Filled' type.
6464
ElevatedButton(
6565
style: ElevatedButton.styleFrom(
66-
// Foreground color
67-
onPrimary: Theme.of(context).colorScheme.onPrimary,
68-
// Background color
69-
primary: Theme.of(context).colorScheme.primary,
66+
foregroundColor: Theme.of(context).colorScheme.onPrimary,
67+
backgroundColor: Theme.of(context).colorScheme.primary,
7068
).copyWith(elevation: ButtonStyleButton.allOrNull(0.0)),
7169
onPressed: onPressed,
7270
child: const Text('Filled'),
@@ -76,10 +74,8 @@ class ButtonTypesGroup extends StatelessWidget {
7674
// 'Filled Tonal' type.
7775
ElevatedButton(
7876
style: ElevatedButton.styleFrom(
79-
// Foreground color
80-
onPrimary: Theme.of(context).colorScheme.onSecondaryContainer,
81-
// Background color
82-
primary: Theme.of(context).colorScheme.secondaryContainer,
77+
foregroundColor: Theme.of(context).colorScheme.onSecondaryContainer,
78+
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
8379
).copyWith(elevation: ButtonStyleButton.allOrNull(0.0)),
8480
onPressed: onPressed,
8581
child: const Text('Filled Tonal'),

examples/api/lib/material/navigation_bar/navigation_bar.0.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class RootPage extends StatelessWidget {
3535
Widget build(BuildContext context) {
3636
final TextStyle headline5 = Theme.of(context).textTheme.headline5!;
3737
final ButtonStyle buttonStyle = ElevatedButton.styleFrom(
38-
primary: destination.color,
38+
backgroundColor: destination.color,
3939
visualDensity: VisualDensity.comfortable,
4040
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
4141
textStyle: headline5,
@@ -125,7 +125,7 @@ class ListPage extends StatelessWidget {
125125
Widget build(BuildContext context) {
126126
const int itemCount = 50;
127127
final ButtonStyle buttonStyle = OutlinedButton.styleFrom(
128-
primary: destination.color,
128+
foregroundColor: destination.color,
129129
fixedSize: const Size.fromHeight(128),
130130
textStyle: Theme.of(context).textTheme.headline5,
131131
);

examples/api/lib/material/text_button/text_button.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class MyStatelessWidget extends StatelessWidget {
6969
),
7070
TextButton(
7171
style: TextButton.styleFrom(
72+
foregroundColor: Colors.white,
7273
padding: const EdgeInsets.all(16.0),
73-
primary: Colors.white,
7474
textStyle: const TextStyle(fontSize: 20),
7575
),
7676
onPressed: () {},

examples/api/lib/widgets/basic/absorb_pointer.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MyStatelessWidget extends StatelessWidget {
4949
child: AbsorbPointer(
5050
child: ElevatedButton(
5151
style: ElevatedButton.styleFrom(
52-
primary: Colors.blue.shade200,
52+
backgroundColor: Colors.blue.shade200,
5353
),
5454
onPressed: () {},
5555
child: null,

packages/flutter/lib/fix_data.yaml

+161
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,167 @@
1717

1818
version: 1
1919
transforms:
20+
# Changes made in https://github.com/flutter/flutter/pull/105291
21+
- title: "Migrate 'ElevatedButton.styleFrom(primary)' to 'ElevatedButton.styleFrom(backgroundColor)'"
22+
date: 2022-05-27
23+
element:
24+
uris: [ 'material.dart' ]
25+
method: 'styleFrom'
26+
inClass: 'ElevatedButton'
27+
changes:
28+
- kind: 'addParameter'
29+
index: 1
30+
name: 'backgroundColor'
31+
style: optional_named
32+
argumentValue:
33+
expression: '{% primary %}'
34+
requiredIf: "primary != ''"
35+
- kind: 'removeParameter'
36+
name: 'primary'
37+
variables:
38+
primary:
39+
kind: 'fragment'
40+
value: 'arguments[primary]'
41+
42+
# Changes made in https://github.com/flutter/flutter/pull/105291
43+
- title: "Migrate 'ElevatedButton.styleFrom(onPrimary)' to 'ElevatedButton.styleFrom(foregroundColor)'"
44+
date: 2022-05-27
45+
element:
46+
uris: [ 'material.dart' ]
47+
method: 'styleFrom'
48+
inClass: 'ElevatedButton'
49+
changes:
50+
- kind: 'addParameter'
51+
index: 0
52+
name: 'foregroundColor'
53+
style: optional_named
54+
argumentValue:
55+
expression: '{% onPrimary %}'
56+
requiredIf: "onPrimary != ''"
57+
- kind: 'removeParameter'
58+
name: 'onPrimary'
59+
variables:
60+
onPrimary:
61+
kind: 'fragment'
62+
value: 'arguments[onPrimary]'
63+
64+
# Changes made in https://github.com/flutter/flutter/pull/105291
65+
- title: "Migrate 'ElevatedButton.styleFrom(onSurface)' to 'ElevatedButton.styleFrom(disabledForegroundColor)'"
66+
date: 2022-05-27
67+
element:
68+
uris: [ 'material.dart' ]
69+
method: 'styleFrom'
70+
inClass: 'ElevatedButton'
71+
changes:
72+
- kind: 'addParameter'
73+
index: 2
74+
name: 'disabledForegroundColor'
75+
style: optional_named
76+
argumentValue:
77+
expression: '{% onSurface %}.withOpacity(0.38)'
78+
requiredIf: "onSurface != ''"
79+
- kind: 'addParameter'
80+
index: 3
81+
name: 'disabledBackgroundColor'
82+
style: optional_named
83+
argumentValue:
84+
expression: '{% onSurface %}.withOpacity(0.12)'
85+
requiredIf: "onSurface != ''"
86+
- kind: 'removeParameter'
87+
name: 'onSurface'
88+
variables:
89+
onSurface:
90+
kind: 'fragment'
91+
value: 'arguments[onSurface]'
92+
93+
# Changes made in https://github.com/flutter/flutter/pull/105291
94+
- title: "Migrate 'OutlinedButton.styleFrom(primary)' to 'OutlinedButton.styleFrom(foregroundColor)'"
95+
date: 2022-05-27
96+
element:
97+
uris: [ 'material.dart' ]
98+
method: 'styleFrom'
99+
inClass: 'OutlinedButton'
100+
changes:
101+
- kind: 'addParameter'
102+
index: 0
103+
name: 'foregroundColor'
104+
style: optional_named
105+
argumentValue:
106+
expression: '{% primary %}'
107+
requiredIf: "primary != ''"
108+
- kind: 'removeParameter'
109+
name: 'primary'
110+
variables:
111+
primary:
112+
kind: 'fragment'
113+
value: 'arguments[primary]'
114+
115+
# Changes made in https://github.com/flutter/flutter/pull/105291
116+
- title: "Migrate 'OutlinedButton.styleFrom(onSurface)' to 'OutlinedButton.styleFrom(disabledForeground)'"
117+
date: 2022-05-27
118+
element:
119+
uris: [ 'material.dart' ]
120+
method: 'styleFrom'
121+
inClass: 'OutlinedButton'
122+
changes:
123+
- kind: 'addParameter'
124+
index: 2
125+
name: 'disabledForegroundColor'
126+
style: optional_named
127+
argumentValue:
128+
expression: '{% onSurface %}.withOpacity(0.38)'
129+
requiredIf: "onSurface != ''"
130+
- kind: 'removeParameter'
131+
name: 'onSurface'
132+
variables:
133+
onSurface:
134+
kind: 'fragment'
135+
value: 'arguments[onSurface]'
136+
137+
# Changes made in https://github.com/flutter/flutter/pull/105291
138+
- title: "Migrate 'TextButton.styleFrom(primary)' to 'TextButton.styleFrom(foregroundColor)'"
139+
date: 2022-05-27
140+
element:
141+
uris: [ 'material.dart' ]
142+
method: 'styleFrom'
143+
inClass: 'TextButton'
144+
changes:
145+
- kind: 'addParameter'
146+
index: 0
147+
name: 'foregroundColor'
148+
style: optional_named
149+
argumentValue:
150+
expression: '{% primary %}'
151+
requiredIf: "primary != ''"
152+
- kind: 'removeParameter'
153+
name: 'primary'
154+
variables:
155+
primary:
156+
kind: 'fragment'
157+
value: 'arguments[primary]'
158+
159+
# Changes made in https://github.com/flutter/flutter/pull/105291
160+
- title: "Migrate 'TextButton.styleFrom(onSurface)' to 'TextButton.styleFrom(disabledForeground)'"
161+
date: 2022-05-27
162+
element:
163+
uris: [ 'material.dart' ]
164+
method: 'styleFrom'
165+
inClass: 'TextButton'
166+
changes:
167+
- kind: 'addParameter'
168+
index: 2
169+
name: 'disabledForegroundColor'
170+
style: optional_named
171+
argumentValue:
172+
expression: '{% onSurface %}.withOpacity(0.38)'
173+
requiredIf: "onSurface != ''"
174+
- kind: 'removeParameter'
175+
name: 'onSurface'
176+
variables:
177+
onSurface:
178+
kind: 'fragment'
179+
value: 'arguments[onSurface]'
180+
20181
# Changes made in https://github.com/flutter/flutter/pull/100381
21182
- title: "Migrate 'TextSelectionOverlay.fadeDuration' to SelectionOverlay.fadeDuration"
22183
date: 2022-03-18

0 commit comments

Comments
 (0)