refactor: Improve delete device UX flow

pull/1411/head
krille-chan 1 year ago
parent 38283d2b27
commit d14698ee94
No known key found for this signature in database

@ -9,7 +9,6 @@ import 'package:matrix/matrix.dart';
import 'package:fluffychat/pages/device_settings/device_settings_view.dart';
import 'package:fluffychat/pages/key_verification/key_verification_dialog.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import '../../widgets/matrix.dart';
class DevicesSettings extends StatefulWidget {
@ -29,9 +28,6 @@ class DevicesSettingsController extends State<DevicesSettings> {
void reload() => setState(() => devices = null);
bool loadingDeletingDevices = false;
String? errorDeletingDevices;
bool? chatBackupEnabled;
@override
@ -69,24 +65,16 @@ class DevicesSettingsController extends State<DevicesSettings> {
deviceIds.add(userDevice.deviceId);
}
try {
setState(() {
loadingDeletingDevices = true;
errorDeletingDevices = null;
});
await matrix.client.uiaRequestBackground(
await showFutureLoadingDialog(
context: context,
future: () => matrix.client.uiaRequestBackground(
(auth) => matrix.client.deleteDevices(
deviceIds,
auth: auth,
),
);
reload();
} catch (e, s) {
Logs().w('Error while deleting devices', e, s);
setState(() => errorDeletingDevices = e.toLocalizedString(context));
} finally {
setState(() => loadingDeletingDevices = false);
}
),
);
reload();
}
void renameDeviceAction(Device device) async {

@ -96,8 +96,7 @@ class DevicesSettingsView extends StatelessWidget {
width: double.infinity,
child: TextButton.icon(
label: Text(
controller.errorDeletingDevices ??
L10n.of(context).removeAllOtherDevices,
L10n.of(context).removeAllOtherDevices,
),
style: TextButton.styleFrom(
foregroundColor:
@ -105,16 +104,10 @@ class DevicesSettingsView extends StatelessWidget {
backgroundColor:
theme.colorScheme.errorContainer,
),
icon: controller.loadingDeletingDevices
? const CircularProgressIndicator.adaptive(
strokeWidth: 2,
)
: const Icon(Icons.delete_outline),
onPressed: controller.loadingDeletingDevices
? null
: () => controller.removeDevicesAction(
controller.notThisDevice,
),
icon: const Icon(Icons.delete_outline),
onPressed: () => controller.removeDevicesAction(
controller.notThisDevice,
),
),
),
)

@ -5,11 +5,15 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
import 'package:fluffychat/widgets/matrix.dart';
extension UiaRequestManager on MatrixState {
Future uiaRequestHandler(UiaRequest uiaRequest) async {
final l10n = L10n.of(context);
final navigatorContext =
FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ??
context;
try {
if (uiaRequest.state != UiaRequestState.waitForUser ||
uiaRequest.nextStages.isEmpty) {
@ -22,7 +26,7 @@ extension UiaRequestManager on MatrixState {
case AuthenticationTypes.password:
final input = cachedPassword ??
(await showTextInputDialog(
context: context,
context: navigatorContext,
title: l10n.pleaseEnterYourPassword,
okLabel: l10n.ok,
cancelLabel: l10n.cancel,
@ -63,7 +67,7 @@ extension UiaRequestManager on MatrixState {
if (OkCancelResult.ok ==
await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
context: navigatorContext,
title: l10n.weSentYouAnEmail,
message: l10n.pleaseClickOnLink,
okLabel: l10n.iHaveClickedOnLink,
@ -88,7 +92,7 @@ extension UiaRequestManager on MatrixState {
await showOkCancelAlertDialog(
useRootNavigator: false,
message: l10n.pleaseFollowInstructionsOnWeb,
context: context,
context: navigatorContext,
okLabel: l10n.next,
cancelLabel: l10n.cancel,
)) {

Loading…
Cancel
Save