refactor: Switch to loading dialog
This commit is contained in:
parent
9521a93622
commit
75797a62b9
36 changed files with 461 additions and 350 deletions
|
|
@ -2,7 +2,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart';
|
|||
import 'package:famedlysdk/encryption.dart';
|
||||
import 'package:famedlysdk/encryption/utils/bootstrap.dart';
|
||||
import 'package:fluffychat/components/dialogs/adaptive_flat_button.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -119,11 +119,12 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
|
|||
)
|
||||
]);
|
||||
if (input?.isEmpty ?? true) return;
|
||||
final valid =
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
bootstrap.newSsssKey.unlock(keyOrPassphrase: input.single),
|
||||
final valid = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
bootstrap.newSsssKey.unlock(keyOrPassphrase: input.single),
|
||||
);
|
||||
if (valid != false) bootstrap.openExistingSsss();
|
||||
if (valid.error == null) bootstrap.openExistingSsss();
|
||||
}));
|
||||
break;
|
||||
case BootstrapState.askWipeCrossSigning:
|
||||
|
|
@ -237,9 +238,12 @@ class _AskUnlockOldSsssState extends State<_AskUnlockOldSsss> {
|
|||
return;
|
||||
}
|
||||
|
||||
valid = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.ssssKey.unlock(keyOrPassphrase: input),
|
||||
);
|
||||
valid = (await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => widget.ssssKey.unlock(keyOrPassphrase: input),
|
||||
))
|
||||
.error ==
|
||||
null;
|
||||
setState(() => null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import '../avatar.dart';
|
||||
import 'adaptive_flat_button.dart';
|
||||
import 'simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import '../../utils/string_color.dart';
|
||||
|
||||
class KeyVerificationDialog extends StatefulWidget {
|
||||
|
|
@ -70,25 +70,26 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
if (input == null) {
|
||||
return;
|
||||
}
|
||||
final valid = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(Future.microtask(() async {
|
||||
// make sure the loading spinner shows before we test the keys
|
||||
await Future.delayed(Duration(milliseconds: 100));
|
||||
var valid = false;
|
||||
try {
|
||||
await widget.request.openSSSS(recoveryKey: input);
|
||||
valid = true;
|
||||
} catch (_) {
|
||||
try {
|
||||
await widget.request.openSSSS(passphrase: input);
|
||||
valid = true;
|
||||
} catch (_) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}));
|
||||
if (valid == false) {
|
||||
final valid = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
// make sure the loading spinner shows before we test the keys
|
||||
await Future.delayed(Duration(milliseconds: 100));
|
||||
var valid = false;
|
||||
try {
|
||||
await widget.request.openSSSS(recoveryKey: input);
|
||||
valid = true;
|
||||
} catch (_) {
|
||||
try {
|
||||
await widget.request.openSSSS(passphrase: input);
|
||||
valid = true;
|
||||
} catch (_) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
});
|
||||
if (valid.error != null) {
|
||||
await showOkAlertDialog(
|
||||
context: context,
|
||||
message: L10n.of(context).incorrectPassphraseOrKey,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'package:famedlysdk/famedlysdk.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import '../../components/dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import '../../utils/matrix_file_extension.dart';
|
||||
import '../../utils/room_send_file_extension.dart';
|
||||
import '../../utils/resize_image.dart';
|
||||
|
|
@ -88,8 +88,8 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
|||
setState(() {
|
||||
_isSending = true;
|
||||
});
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(_send());
|
||||
await showFutureLoadingDialog(
|
||||
context: context, future: () => _send());
|
||||
await Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class SimpleDialogs {
|
||||
final BuildContext context;
|
||||
|
||||
const SimpleDialogs(this.context);
|
||||
|
||||
Future<dynamic> tryRequestWithLoadingDialog(Future<dynamic> request,
|
||||
{Function(MatrixException) onAdditionalAuth}) async {
|
||||
final futureResult = tryRequestWithErrorToast(
|
||||
request,
|
||||
onAdditionalAuth: onAdditionalAuth,
|
||||
);
|
||||
return showDialog<dynamic>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
futureResult.then(
|
||||
(result) => Navigator.of(context).pop<dynamic>(result),
|
||||
);
|
||||
return AlertDialog(
|
||||
title: Text(L10n.of(context).loadingPleaseWait),
|
||||
content: LinearProgressIndicator(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<dynamic> tryRequestWithErrorToast(Future<dynamic> request,
|
||||
{Function(MatrixException) onAdditionalAuth}) async {
|
||||
try {
|
||||
return await request;
|
||||
} on MatrixException catch (exception) {
|
||||
if (exception.requireAdditionalAuthentication &&
|
||||
onAdditionalAuth != null) {
|
||||
return await tryRequestWithErrorToast(onAdditionalAuth(exception));
|
||||
} else {
|
||||
await FlushbarHelper.createError(message: exception.errorMessage)
|
||||
.show(context);
|
||||
}
|
||||
} catch (exception) {
|
||||
await FlushbarHelper.createError(message: exception.toString())
|
||||
.show(context);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue