Skip to content

Commit 8d6be3e

Browse files
committed
wip
1 parent 0f0fa80 commit 8d6be3e

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

packages/firebase_ui_auth/example/lib/main.dart

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ class FirebaseAuthUIExample extends StatelessWidget {
267267
showMFATile: kIsWeb ||
268268
platform == TargetPlatform.iOS ||
269269
platform == TargetPlatform.android,
270+
showUnlinkConfirmationDialog: true,
270271
);
271272
},
272273
},

packages/firebase_ui_auth/example/windows/flutter/generated_plugin_registrant.cc

+3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
#include "generated_plugin_registrant.h"
88

99
#include <desktop_webview_auth/desktop_webview_auth_plugin.h>
10+
#include <firebase_auth/firebase_auth_plugin_c_api.h>
1011
#include <firebase_core/firebase_core_plugin_c_api.h>
1112
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
1213

1314
void RegisterPlugins(flutter::PluginRegistry* registry) {
1415
DesktopWebviewAuthPluginRegisterWithRegistrar(
1516
registry->GetRegistrarForPlugin("DesktopWebviewAuthPlugin"));
17+
FirebaseAuthPluginCApiRegisterWithRegistrar(
18+
registry->GetRegistrarForPlugin("FirebaseAuthPluginCApi"));
1619
FirebaseCorePluginCApiRegisterWithRegistrar(
1720
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
1821
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(

packages/firebase_ui_auth/example/windows/flutter/generated_plugins.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
list(APPEND FLUTTER_PLUGIN_LIST
66
desktop_webview_auth
7+
firebase_auth
78
firebase_core
89
flutter_secure_storage_windows
910
)

packages/firebase_ui_auth/lib/src/screens/profile_screen.dart

+32
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ class _LinkedProvidersRow extends StatefulWidget {
176176
final FirebaseAuth? auth;
177177
final List<AuthProvider> providers;
178178
final VoidCallback onProviderUnlinked;
179+
final bool showUnlinkConfirmationDialog;
179180

180181
const _LinkedProvidersRow({
181182
this.auth,
182183
required this.providers,
183184
required this.onProviderUnlinked,
185+
required this.showUnlinkConfirmationDialog,
184186
});
185187

186188
@override
@@ -207,7 +209,31 @@ class _LinkedProvidersRowState extends State<_LinkedProvidersRow> {
207209
error = null;
208210
});
209211

212+
bool? confirmed = !widget.showUnlinkConfirmationDialog;
213+
214+
if (!confirmed) {
215+
confirmed = await showAdaptiveDialog<bool?>(
216+
context: context,
217+
builder: (context) {
218+
return UniversalAlert(
219+
onConfirm: () {
220+
Navigator.of(context).pop(true);
221+
},
222+
onCancel: () {
223+
Navigator.of(context).pop(false);
224+
},
225+
title: 'Unlink provider',
226+
confirmButtonText: 'Unlink',
227+
cancelButtonText: 'Cancel',
228+
message: 'Are you sure you want to unlink this provider?',
229+
);
230+
},
231+
);
232+
}
233+
210234
try {
235+
if (!(confirmed ?? false)) return;
236+
211237
final user = widget.auth!.currentUser!;
212238
await user.unlink(providerId);
213239
await user.reload();
@@ -712,6 +738,10 @@ class ProfileScreen extends MultiProviderScreen {
712738
/// are ignored.
713739
final Widget? avatar;
714740

741+
/// Indicates wether a confirmation dialog should be shown when the user
742+
/// tries to unlink a provider.
743+
final bool showUnlinkConfirmationDialog;
744+
715745
const ProfileScreen({
716746
super.key,
717747
super.auth,
@@ -726,6 +756,7 @@ class ProfileScreen extends MultiProviderScreen {
726756
this.cupertinoNavigationBar,
727757
this.actionCodeSettings,
728758
this.showMFATile = false,
759+
this.showUnlinkConfirmationDialog = false,
729760
});
730761

731762
Future<bool> _reauthenticate(BuildContext context) {
@@ -819,6 +850,7 @@ class ProfileScreen extends MultiProviderScreen {
819850
auth: auth,
820851
providers: linkedProviders,
821852
onProviderUnlinked: providersScopeKey.rebuild,
853+
showUnlinkConfirmationDialog: showUnlinkConfirmationDialog,
822854
),
823855
);
824856
},

packages/firebase_ui_shared/lib/firebase_ui_shared.dart

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export 'src/universal_scaffold.dart' show UniversalScaffold;
99
export 'src/universal_icon.dart' show UniversalIcon;
1010
export 'src/universal_button.dart' show UniversalButton, ButtonVariant;
1111
export 'src/loading_button.dart' show LoadingButton;
12+
export 'src/universal_alert.dart' show UniversalAlert;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
4+
class UniversalAlert extends StatelessWidget {
5+
final void Function() onConfirm;
6+
final void Function() onCancel;
7+
8+
final String title;
9+
final String message;
10+
11+
final String confirmButtonText;
12+
final String cancelButtonText;
13+
14+
const UniversalAlert({
15+
super.key,
16+
required this.onConfirm,
17+
required this.onCancel,
18+
required this.title,
19+
required this.confirmButtonText,
20+
required this.cancelButtonText,
21+
required this.message,
22+
});
23+
24+
Widget adaptiveAction({
25+
required BuildContext context,
26+
required VoidCallback onPressed,
27+
required Widget child,
28+
bool isDestructiveAction = false,
29+
}) {
30+
final ThemeData theme = Theme.of(context);
31+
switch (theme.platform) {
32+
case TargetPlatform.android:
33+
case TargetPlatform.fuchsia:
34+
case TargetPlatform.linux:
35+
case TargetPlatform.windows:
36+
return TextButton(onPressed: onPressed, child: child);
37+
case TargetPlatform.iOS:
38+
case TargetPlatform.macOS:
39+
return CupertinoDialogAction(
40+
onPressed: onPressed,
41+
isDestructiveAction: isDestructiveAction,
42+
child: child,
43+
);
44+
}
45+
}
46+
47+
@override
48+
Widget build(BuildContext context) {
49+
return AlertDialog.adaptive(
50+
title: Text(title),
51+
content: Text(message),
52+
actions: [
53+
adaptiveAction(
54+
context: context,
55+
onPressed: onConfirm,
56+
child: Text(confirmButtonText),
57+
isDestructiveAction: true,
58+
),
59+
adaptiveAction(
60+
context: context,
61+
onPressed: onCancel,
62+
child: Text(cancelButtonText),
63+
),
64+
],
65+
);
66+
}
67+
}

0 commit comments

Comments
 (0)