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.
This commit is contained in:
Darren Austin
2022-06-21 19:08:22 -07:00
committed by GitHub
parent ce10e6fff2
commit 2532584bf3
21 changed files with 404 additions and 106 deletions

View File

@@ -25,7 +25,7 @@ class AppBarExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ButtonStyle style = TextButton.styleFrom(
primary: Theme.of(context).colorScheme.onPrimary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
);
return Scaffold(
appBar: AppBar(

View File

@@ -63,10 +63,8 @@ class ButtonTypesGroup extends StatelessWidget {
// 'Filled' type.
ElevatedButton(
style: ElevatedButton.styleFrom(
// Foreground color
onPrimary: Theme.of(context).colorScheme.onPrimary,
// Background color
primary: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
backgroundColor: Theme.of(context).colorScheme.primary,
).copyWith(elevation: ButtonStyleButton.allOrNull(0.0)),
onPressed: onPressed,
child: const Text('Filled'),
@@ -76,10 +74,8 @@ class ButtonTypesGroup extends StatelessWidget {
// 'Filled Tonal' type.
ElevatedButton(
style: ElevatedButton.styleFrom(
// Foreground color
onPrimary: Theme.of(context).colorScheme.onSecondaryContainer,
// Background color
primary: Theme.of(context).colorScheme.secondaryContainer,
foregroundColor: Theme.of(context).colorScheme.onSecondaryContainer,
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
).copyWith(elevation: ButtonStyleButton.allOrNull(0.0)),
onPressed: onPressed,
child: const Text('Filled Tonal'),

View File

@@ -35,7 +35,7 @@ class RootPage extends StatelessWidget {
Widget build(BuildContext context) {
final TextStyle headline5 = Theme.of(context).textTheme.headline5!;
final ButtonStyle buttonStyle = ElevatedButton.styleFrom(
primary: destination.color,
backgroundColor: destination.color,
visualDensity: VisualDensity.comfortable,
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
textStyle: headline5,
@@ -125,7 +125,7 @@ class ListPage extends StatelessWidget {
Widget build(BuildContext context) {
const int itemCount = 50;
final ButtonStyle buttonStyle = OutlinedButton.styleFrom(
primary: destination.color,
foregroundColor: destination.color,
fixedSize: const Size.fromHeight(128),
textStyle: Theme.of(context).textTheme.headline5,
);

View File

@@ -69,8 +69,8 @@ class MyStatelessWidget extends StatelessWidget {
),
TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.white,
padding: const EdgeInsets.all(16.0),
primary: Colors.white,
textStyle: const TextStyle(fontSize: 20),
),
onPressed: () {},

View File

@@ -49,7 +49,7 @@ class MyStatelessWidget extends StatelessWidget {
child: AbsorbPointer(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.blue.shade200,
backgroundColor: Colors.blue.shade200,
),
onPressed: () {},
child: null,