Skip to content

Commit a541e9a

Browse files
authored
fix(ui_auth): fix material 3 button styling (#10253)
1 parent f3a4d3a commit a541e9a

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

packages/firebase_ui_auth/example/lib/main.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:firebase_ui_oauth_apple/firebase_ui_oauth_apple.dart';
1111
import 'package:firebase_ui_oauth_facebook/firebase_ui_oauth_facebook.dart';
1212
import 'package:firebase_ui_oauth_google/firebase_ui_oauth_google.dart';
1313
import 'package:firebase_ui_oauth_twitter/firebase_ui_oauth_twitter.dart';
14+
import 'package:flutter/foundation.dart';
1415
import 'package:flutter/material.dart';
1516
import 'package:flutter_localizations/flutter_localizations.dart';
1617

@@ -107,6 +108,7 @@ class FirebaseAuthUIExample extends StatelessWidget {
107108
theme: ThemeData(
108109
brightness: Brightness.light,
109110
visualDensity: VisualDensity.standard,
111+
useMaterial3: true,
110112
inputDecorationTheme: const InputDecorationTheme(
111113
border: OutlineInputBorder(),
112114
),
@@ -260,6 +262,8 @@ class FirebaseAuthUIExample extends StatelessWidget {
260262
);
261263
},
262264
'/profile': (context) {
265+
final platform = Theme.of(context).platform;
266+
263267
return ProfileScreen(
264268
actions: [
265269
SignedOutAction((context) {
@@ -268,7 +272,9 @@ class FirebaseAuthUIExample extends StatelessWidget {
268272
mfaAction,
269273
],
270274
actionCodeSettings: actionCodeSettings,
271-
showMFATile: true,
275+
showMFATile: kIsWeb ||
276+
platform == TargetPlatform.iOS ||
277+
platform == TargetPlatform.android,
272278
);
273279
},
274280
},

packages/firebase_ui_auth/lib/src/widgets/delete_account_button.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,15 @@ class _DeleteAccountButtonState extends State<DeleteAccountButton> {
8080
final l = FirebaseUILocalizations.labelsOf(context);
8181
bool isCupertino = CupertinoUserInterfaceLevel.maybeOf(context) != null;
8282

83+
final themeData = Theme.of(context);
84+
final colorScheme = themeData.colorScheme;
85+
8386
return LoadingButton(
8487
isLoading: _isLoading,
85-
color: isCupertino ? CupertinoColors.destructiveRed : Colors.red,
88+
color: isCupertino ? CupertinoColors.destructiveRed : colorScheme.error,
8689
icon: isCupertino ? CupertinoIcons.delete : Icons.delete,
8790
label: l.deleteAccount,
91+
labelColor: colorScheme.onError,
8892
onTap: _deleteAccount,
8993
variant: widget.variant,
9094
);

packages/firebase_ui_auth/lib/src/widgets/internal/loading_button.dart

+23-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ class _LoadingButtonContent extends StatelessWidget {
2222
@override
2323
Widget build(BuildContext context) {
2424
bool isCupertino = CupertinoUserInterfaceLevel.maybeOf(context) != null;
25+
Widget child;
2526

26-
Widget child = Text(label);
27+
if (color != null) {
28+
final theme = Theme.of(context).textTheme.button;
29+
child = Text(
30+
label,
31+
style: theme?.copyWith(color: color),
32+
);
33+
} else {
34+
child = Text(label);
35+
}
2736

2837
if (isLoading) {
2938
child = LoadingIndicator(
@@ -42,6 +51,7 @@ class LoadingButton extends StatelessWidget {
4251
final String label;
4352
final IconData? icon;
4453
final Color? color;
54+
final Color? labelColor;
4555
final VoidCallback onTap;
4656
final ButtonVariant? variant;
4757

@@ -52,22 +62,31 @@ class LoadingButton extends StatelessWidget {
5262
this.isLoading = false,
5363
this.icon,
5464
this.color,
65+
this.labelColor,
5566
this.variant = ButtonVariant.outlined,
5667
}) : super(key: key);
5768

5869
@override
5970
Widget build(BuildContext context) {
71+
final theme = Theme.of(context);
72+
final isMaterial3 = theme.useMaterial3;
73+
74+
final resolvedColor = variant == ButtonVariant.filled && !isMaterial3
75+
? theme.colorScheme.onPrimary
76+
: null;
77+
78+
final contentColor = labelColor ?? resolvedColor;
79+
6080
final content = _LoadingButtonContent(
6181
label: label,
6282
isLoading: isLoading,
63-
color: variant == ButtonVariant.filled
64-
? Theme.of(context).colorScheme.onPrimary
65-
: null,
83+
color: contentColor,
6684
);
6785

6886
return UniversalButton(
6987
color: color,
7088
icon: icon,
89+
contentColor: contentColor,
7190
onPressed: onTap,
7291
variant: variant,
7392
child: content,

packages/firebase_ui_auth/lib/src/widgets/internal/universal_button.dart

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class UniversalButton extends PlatformWidget {
2929
final TextDirection? direction;
3030
final ButtonVariant? variant;
3131
final Color? color;
32+
final Color? contentColor;
3233

3334
const UniversalButton({
3435
Key? key,
@@ -39,6 +40,7 @@ class UniversalButton extends PlatformWidget {
3940
this.direction = TextDirection.ltr,
4041
this.variant,
4142
this.color,
43+
this.contentColor,
4244
}) : assert(text != null || child != null),
4345
super(key: key);
4446

@@ -56,7 +58,7 @@ class UniversalButton extends PlatformWidget {
5658
children: [
5759
if (icon != null) ...[
5860
if (direction == TextDirection.rtl) const SizedBox(width: 8),
59-
Icon(icon, size: 20),
61+
Icon(icon, size: 20, color: contentColor),
6062
if (direction == TextDirection.ltr) const SizedBox(width: 8),
6163
],
6264
this.child ?? Text(text!),
@@ -99,6 +101,7 @@ class UniversalButton extends PlatformWidget {
99101
if (variant == ButtonVariant.text) {
100102
foregroundColor = MaterialStateColor.resolveWith((_) => color!);
101103
} else {
104+
foregroundColor = MaterialStateColor.resolveWith((_) => contentColor!);
102105
backgroundColor = MaterialStateColor.resolveWith((_) => color!);
103106
}
104107

@@ -115,22 +118,22 @@ class UniversalButton extends PlatformWidget {
115118
switch (_variant) {
116119
case ButtonVariant.text:
117120
return TextButton.icon(
118-
icon: Icon(icon),
121+
icon: Icon(icon, color: contentColor),
119122
onPressed: onPressed,
120123
label: child,
121124
style: style,
122125
);
123126
case ButtonVariant.filled:
124127
return ElevatedButton.icon(
125128
onPressed: onPressed,
126-
icon: Icon(icon),
129+
icon: Icon(icon, color: contentColor),
127130
label: child,
128131
style: style,
129132
);
130133
case ButtonVariant.outlined:
131134
return OutlinedButton.icon(
132135
onPressed: onPressed,
133-
icon: Icon(icon),
136+
icon: Icon(icon, color: contentColor),
134137
label: child,
135138
style: style,
136139
);

0 commit comments

Comments
 (0)