refactor: Switch to loading dialog

This commit is contained in:
Christian Pauly 2020-12-25 09:58:34 +01:00
parent 66fc2e0bce
commit e84bc25602
36 changed files with 461 additions and 350 deletions

View File

@ -3,12 +3,12 @@ import 'dart:typed_data';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/message_download_content.dart'; import 'package:fluffychat/components/message_download_content.dart';
import 'package:flushbar/flushbar_helper.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_sound/flutter_sound.dart'; import 'package:flutter_sound/flutter_sound.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:universal_html/prefer_universal/html.dart' as html; import 'package:universal_html/prefer_universal/html.dart' as html;
import 'dialogs/simple_dialogs.dart';
import '../utils/ui_fake.dart' if (dart.library.html) 'dart:ui' as ui; import '../utils/ui_fake.dart' if (dart.library.html) 'dart:ui' as ui;
import 'matrix.dart'; import 'matrix.dart';
import '../utils/event_extension.dart'; import '../utils/event_extension.dart';
@ -68,13 +68,19 @@ class _AudioPlayerState extends State<AudioPlayer> {
Future<void> _downloadAction() async { Future<void> _downloadAction() async {
if (status != AudioPlayerStatus.NOT_DOWNLOADED) return; if (status != AudioPlayerStatus.NOT_DOWNLOADED) return;
setState(() => status = AudioPlayerStatus.DOWNLOADING); setState(() => status = AudioPlayerStatus.DOWNLOADING);
final matrixFile = await SimpleDialogs(context).tryRequestWithErrorToast( try {
widget.event.downloadAndDecryptAttachmentCached()); final matrixFile =
setState(() { await widget.event.downloadAndDecryptAttachmentCached();
audioFile = matrixFile.bytes; setState(() {
status = AudioPlayerStatus.DOWNLOADED; audioFile = matrixFile.bytes;
}); status = AudioPlayerStatus.DOWNLOADED;
_playAction(); });
_playAction();
} catch (e, s) {
Logs().v('Could not download audio file', e, s);
await FlushbarHelper.createError(message: e.toLocalizedString(context))
.show(context);
}
} }
void _playAction() async { void _playAction() async {

View File

@ -10,7 +10,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import '../app_config.dart'; import '../app_config.dart';
import 'dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'matrix.dart'; import 'matrix.dart';
class ChatSettingsPopupMenu extends StatefulWidget { class ChatSettingsPopupMenu extends StatefulWidget {
@ -35,12 +35,13 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
void startCallAction(BuildContext context) async { void startCallAction(BuildContext context) async {
final url = final url =
'${AppConfig.jitsiInstance}${Uri.encodeComponent(widget.room.id.localpart)}'; '${AppConfig.jitsiInstance}${Uri.encodeComponent(widget.room.id.localpart)}';
final success = await SimpleDialogs(context) final success = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(widget.room.sendEvent({ context: context,
'msgtype': Matrix.callNamespace, future: () => widget.room.sendEvent({
'body': url, 'msgtype': Matrix.callNamespace,
})); 'body': url,
if (success == false) return; }));
if (success.error != null) return;
await launch(url); await launch(url);
} }
@ -91,9 +92,9 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
title: L10n.of(context).areYouSure, title: L10n.of(context).areYouSure,
); );
if (confirmed == OkCancelResult.ok) { if (confirmed == OkCancelResult.ok) {
final success = await SimpleDialogs(context) final success = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(widget.room.leave()); context: context, future: () => widget.room.leave());
if (success != false) { if (success.error == null) {
await Navigator.of(context).pushAndRemoveUntil( await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, ChatListView()), AppRoute.defaultRoute(context, ChatListView()),
(Route r) => false); (Route r) => false);
@ -101,12 +102,16 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
} }
break; break;
case 'mute': case 'mute':
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
widget.room.setPushRuleState(PushRuleState.mentions_only)); context: context,
future: () =>
widget.room.setPushRuleState(PushRuleState.mentions_only));
break; break;
case 'unmute': case 'unmute':
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
widget.room.setPushRuleState(PushRuleState.notify)); context: context,
future: () =>
widget.room.setPushRuleState(PushRuleState.notify));
break; break;
case 'call': case 'call':
startCallAction(context); startCallAction(context);

View File

@ -9,7 +9,7 @@ import 'package:fluffychat/views/settings.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'matrix.dart'; import 'matrix.dart';
class DefaultDrawer extends StatelessWidget { class DefaultDrawer extends StatelessWidget {
@ -37,8 +37,9 @@ class DefaultDrawer extends StatelessWidget {
); );
if (input == null || input.single.isEmpty) return; if (input == null || input.single.isEmpty) return;
final client = Matrix.of(context).client; final client = Matrix.of(context).client;
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
client.sendPresence( context: context,
future: () => client.sendPresence(
client.userID, client.userID,
PresenceType.online, PresenceType.online,
statusMsg: input.single, statusMsg: input.single,

View File

@ -2,7 +2,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/encryption.dart'; import 'package:famedlysdk/encryption.dart';
import 'package:famedlysdk/encryption/utils/bootstrap.dart'; import 'package:famedlysdk/encryption/utils/bootstrap.dart';
import 'package:fluffychat/components/dialogs/adaptive_flat_button.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:fluffychat/utils/platform_infos.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -119,11 +119,12 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
) )
]); ]);
if (input?.isEmpty ?? true) return; if (input?.isEmpty ?? true) return;
final valid = final valid = await showFutureLoadingDialog(
await SimpleDialogs(context).tryRequestWithLoadingDialog( context: context,
bootstrap.newSsssKey.unlock(keyOrPassphrase: input.single), future: () =>
bootstrap.newSsssKey.unlock(keyOrPassphrase: input.single),
); );
if (valid != false) bootstrap.openExistingSsss(); if (valid.error == null) bootstrap.openExistingSsss();
})); }));
break; break;
case BootstrapState.askWipeCrossSigning: case BootstrapState.askWipeCrossSigning:
@ -237,9 +238,12 @@ class _AskUnlockOldSsssState extends State<_AskUnlockOldSsss> {
return; return;
} }
valid = await SimpleDialogs(context).tryRequestWithLoadingDialog( valid = (await showFutureLoadingDialog(
widget.ssssKey.unlock(keyOrPassphrase: input), context: context,
); future: () => widget.ssssKey.unlock(keyOrPassphrase: input),
))
.error ==
null;
setState(() => null); setState(() => null);
} }

View File

@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../avatar.dart'; import '../avatar.dart';
import 'adaptive_flat_button.dart'; import 'adaptive_flat_button.dart';
import 'simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import '../../utils/string_color.dart'; import '../../utils/string_color.dart';
class KeyVerificationDialog extends StatefulWidget { class KeyVerificationDialog extends StatefulWidget {
@ -70,25 +70,26 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
if (input == null) { if (input == null) {
return; return;
} }
final valid = await SimpleDialogs(context) final valid = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(Future.microtask(() async { context: context,
// make sure the loading spinner shows before we test the keys future: () async {
await Future.delayed(Duration(milliseconds: 100)); // make sure the loading spinner shows before we test the keys
var valid = false; await Future.delayed(Duration(milliseconds: 100));
try { var valid = false;
await widget.request.openSSSS(recoveryKey: input); try {
valid = true; await widget.request.openSSSS(recoveryKey: input);
} catch (_) { valid = true;
try { } catch (_) {
await widget.request.openSSSS(passphrase: input); try {
valid = true; await widget.request.openSSSS(passphrase: input);
} catch (_) { valid = true;
valid = false; } catch (_) {
} valid = false;
} }
return valid; }
})); return valid;
if (valid == false) { });
if (valid.error != null) {
await showOkAlertDialog( await showOkAlertDialog(
context: context, context: context,
message: L10n.of(context).incorrectPassphraseOrKey, message: L10n.of(context).incorrectPassphraseOrKey,

View File

@ -2,7 +2,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.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/matrix_file_extension.dart';
import '../../utils/room_send_file_extension.dart'; import '../../utils/room_send_file_extension.dart';
import '../../utils/resize_image.dart'; import '../../utils/resize_image.dart';
@ -88,8 +88,8 @@ class _SendFileDialogState extends State<SendFileDialog> {
setState(() { setState(() {
_isSending = true; _isSending = true;
}); });
await SimpleDialogs(context) await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(_send()); context: context, future: () => _send());
await Navigator.of(context).pop(); await Navigator.of(context).pop();
}, },
), ),

View File

@ -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;
}
}

View File

@ -8,7 +8,7 @@ import 'package:fluffychat/views/chat_encryption_settings.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'matrix.dart'; import 'matrix.dart';
class EncryptionButton extends StatefulWidget { class EncryptionButton extends StatefulWidget {
@ -46,8 +46,9 @@ class _EncryptionButtonState extends State<EncryptionButton> {
okLabel: L10n.of(context).yes, okLabel: L10n.of(context).yes,
) == ) ==
OkCancelResult.ok) { OkCancelResult.ok) {
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
widget.room.enableEncryption(), context: context,
future: () => widget.room.enableEncryption(),
); );
// we want to enable the lock icon // we want to enable the lock icon
setState(() => null); setState(() => null);

View File

@ -15,7 +15,7 @@ import '../../utils/date_time_extension.dart';
import '../../views/chat.dart'; import '../../views/chat.dart';
import '../avatar.dart'; import '../avatar.dart';
import '../dialogs/send_file_dialog.dart'; import '../dialogs/send_file_dialog.dart';
import '../dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import '../matrix.dart'; import '../matrix.dart';
import '../mouse_over_builder.dart'; import '../mouse_over_builder.dart';
import '../theme_switcher.dart'; import '../theme_switcher.dart';
@ -41,9 +41,10 @@ class ChatListItem extends StatelessWidget {
if (onTap != null) return onTap(); if (onTap != null) return onTap();
if (!activeChat) { if (!activeChat) {
if (room.membership == Membership.invite && if (room.membership == Membership.invite &&
await SimpleDialogs(context) (await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(room.join()) == context: context, future: () => room.join()))
false) { .error !=
null) {
return; return;
} }
@ -77,8 +78,10 @@ class ChatListItem extends StatelessWidget {
await archiveAction(context); await archiveAction(context);
break; break;
case ArchivedRoomAction.rejoin: case ArchivedRoomAction.rejoin:
await SimpleDialogs(context) await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(room.join()); context: context,
future: () => room.join(),
);
break; break;
} }
} }
@ -111,9 +114,11 @@ class ChatListItem extends StatelessWidget {
Future<void> archiveAction(BuildContext context) async { Future<void> archiveAction(BuildContext context) async {
{ {
if ([Membership.leave, Membership.ban].contains(room.membership)) { if ([Membership.leave, Membership.ban].contains(room.membership)) {
final success = await SimpleDialogs(context) final success = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(room.forget()); context: context,
if (success != false) { future: () => room.forget(),
);
if (success.error == null) {
if (onForget != null) onForget(); if (onForget != null) onForget();
} }
return success; return success;
@ -123,7 +128,8 @@ class ChatListItem extends StatelessWidget {
title: L10n.of(context).areYouSure, title: L10n.of(context).areYouSure,
); );
if (confirmed == OkCancelResult.cancel) return; if (confirmed == OkCancelResult.cancel) return;
await SimpleDialogs(context).tryRequestWithLoadingDialog(room.leave()); await showFutureLoadingDialog(
context: context, future: () => room.leave());
return; return;
} }
} }

View File

@ -1,6 +1,6 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/matrix_api.dart'; import 'package:famedlysdk/matrix_api.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -15,13 +15,15 @@ class PublicRoomListItem extends StatelessWidget {
const PublicRoomListItem(this.publicRoomEntry, {Key key}) : super(key: key); const PublicRoomListItem(this.publicRoomEntry, {Key key}) : super(key: key);
void joinAction(BuildContext context) async { void joinAction(BuildContext context) async {
final success = await SimpleDialogs(context) final success = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(_joinRoomAndWait(context)); context: context,
if (success != false) { future: () => _joinRoomAndWait(context),
);
if (success.error == null) {
await Navigator.of(context).push( await Navigator.of(context).push(
AppRoute.defaultRoute( AppRoute.defaultRoute(
context, context,
ChatView(success), ChatView(success.result),
), ),
); );
} }

View File

@ -1,7 +1,7 @@
import 'package:famedlysdk/encryption/utils/key_verification.dart'; import 'package:famedlysdk/encryption/utils/key_verification.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/audio_player.dart'; import 'package:fluffychat/components/audio_player.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/image_bubble.dart'; import 'package:fluffychat/components/image_bubble.dart';
import 'package:fluffychat/utils/event_extension.dart'; import 'package:fluffychat/utils/event_extension.dart';
import 'package:fluffychat/utils/matrix_locals.dart'; import 'package:fluffychat/utils/matrix_locals.dart';
@ -54,10 +54,11 @@ class MessageContent extends StatelessWidget {
}; };
await KeyVerificationDialog(request: req).show(context); await KeyVerificationDialog(request: req).show(context);
} else { } else {
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
event.requestKey(), context: context,
future: () => event.requestKey(),
); );
if (success != false) { if (success.error == null) {
await FlushbarHelper.createLoading( await FlushbarHelper.createLoading(
title: L10n.of(context).loadingPleaseWait, title: L10n.of(context).loadingPleaseWait,
message: L10n.of(context).requestToReadOlderMessages, message: L10n.of(context).requestToReadOlderMessages,

View File

@ -2,7 +2,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'matrix.dart'; import 'matrix.dart';
class MessageReactions extends StatelessWidget { class MessageReactions extends StatelessWidget {
@ -48,12 +48,16 @@ class MessageReactions extends StatelessWidget {
e.content['m.relates_to']['key'] == r.key, e.content['m.relates_to']['key'] == r.key,
orElse: () => null); orElse: () => null);
if (evt != null) { if (evt != null) {
SimpleDialogs(context) showFutureLoadingDialog(
.tryRequestWithLoadingDialog(evt.redact()); context: context,
future: () => evt.redact(),
);
} }
} else { } else {
SimpleDialogs(context).tryRequestWithLoadingDialog( showFutureLoadingDialog(
event.room.sendReaction(event.eventId, r.key)); context: context,
future: () =>
event.room.sendReaction(event.eventId, r.key));
} }
}, },
)) ))

View File

@ -12,7 +12,7 @@ import 'content_banner.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../utils/presence_extension.dart'; import '../utils/presence_extension.dart';
import 'dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'matrix.dart'; import 'matrix.dart';
import 'dialogs/key_verification_dialog.dart'; import 'dialogs/key_verification_dialog.dart';
import '../utils/app_route.dart'; import '../utils/app_route.dart';
@ -36,20 +36,28 @@ class UserBottomSheet extends StatelessWidget {
break; break;
case 'ban': case 'ban':
if (await _askConfirmation()) { if (await _askConfirmation()) {
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.ban()); await showFutureLoadingDialog(
context: context,
future: () => user.ban(),
);
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
break; break;
case 'unban': case 'unban':
if (await _askConfirmation()) { if (await _askConfirmation()) {
await SimpleDialogs(context) await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(user.unban()); context: context,
future: () => user.unban(),
);
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
break; break;
case 'kick': case 'kick':
if (await _askConfirmation()) { if (await _askConfirmation()) {
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.kick()); await showFutureLoadingDialog(
context: context,
future: () => user.kick(),
);
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
break; break;
@ -59,8 +67,10 @@ class UserBottomSheet extends StatelessWidget {
.show(context); .show(context);
if (newPermission != null) { if (newPermission != null) {
if (newPermission == 100 && await _askConfirmation() == false) break; if (newPermission == 100 && await _askConfirmation() == false) break;
await SimpleDialogs(context) await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(user.setPower(newPermission)); context: context,
future: () => user.setPower(newPermission),
);
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
break; break;

View File

@ -1735,6 +1735,16 @@
"type": {} "type": {}
} }
}, },
"noConnectionToTheServer": "No connection to the server",
"@noConnectionToTheServer": {
"type": "text",
"placeholders": {}
},
"tooManyRequestsWarning": "Too many requests. Please try again later!",
"@tooManyRequestsWarning": {
"type": "text",
"placeholders": {}
},
"unpin": "Unpin", "unpin": "Unpin",
"@unpin": { "@unpin": {
"type": "text", "type": "text",

View File

@ -9,10 +9,12 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:universal_html/prefer_universal/html.dart' as html; import 'package:universal_html/prefer_universal/html.dart' as html;
import 'components/matrix.dart'; import 'components/matrix.dart';
import 'components/theme_switcher.dart'; import 'components/theme_switcher.dart';
import 'utils/localized_exception_extension.dart';
import 'app_config.dart'; import 'app_config.dart';
import 'views/chat_list.dart'; import 'views/chat_list.dart';
@ -50,6 +52,11 @@ class App extends StatelessWidget {
.stream .stream
.first, .first,
builder: (context, snapshot) { builder: (context, snapshot) {
LoadingDialog.defaultTitle =
L10n.of(context).loadingPleaseWait;
LoadingDialog.defaultBackLabel = L10n.of(context).close;
LoadingDialog.defaultOnError =
(Object e) => e.toLocalizedString(context);
if (snapshot.hasError) { if (snapshot.hasError) {
WidgetsBinding.instance.addPostFrameCallback((_) => WidgetsBinding.instance.addPostFrameCallback((_) =>
FlushbarHelper.createError( FlushbarHelper.createError(

View File

@ -1,5 +1,5 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart';
@ -18,11 +18,11 @@ extension LocalizedBody on Event {
); );
return; return;
} }
final MatrixFile matrixFile = final matrixFile = await showFutureLoadingDialog(
await SimpleDialogs(context).tryRequestWithLoadingDialog( context: context,
downloadAndDecryptAttachmentCached(), future: () => downloadAndDecryptAttachmentCached(),
); );
matrixFile.open(); matrixFile.result?.open();
} }
IconData get statusIcon { IconData get statusIcon {

View File

@ -0,0 +1,23 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
extension LocalizedExceptionExtension on Object {
String toLocalizedString(BuildContext context) {
if (this is MatrixException) {
switch ((this as MatrixException).error) {
case MatrixError.M_FORBIDDEN:
return L10n.of(context).noPermission;
case MatrixError.M_LIMIT_EXCEEDED:
return L10n.of(context).tooManyRequestsWarning;
default:
return (this as MatrixException).errorMessage;
}
}
if (this is MatrixConnectionException) {
L10n.of(context).noConnectionToTheServer;
}
Logs().d('Something went wrong: ', this);
return L10n.of(context).oopsSomethingWentWrong;
}
}

View File

@ -1,6 +1,6 @@
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/app_config.dart'; import 'package:fluffychat/app_config.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
@ -44,13 +44,14 @@ class UrlLauncher {
var servers = <String>{}; var servers = <String>{};
if (room == null && roomIdOrAlias.startsWith('#')) { if (room == null && roomIdOrAlias.startsWith('#')) {
// we were unable to find the room locally...so resolve it // we were unable to find the room locally...so resolve it
final response = final response = await showFutureLoadingDialog(
await SimpleDialogs(context).tryRequestWithLoadingDialog( context: context,
matrix.client.requestRoomAliasInformations(roomIdOrAlias), future: () =>
matrix.client.requestRoomAliasInformations(roomIdOrAlias),
); );
if (response != false) { if (response.error == null) {
roomId = response.roomId; roomId = response.result.roomId;
servers.addAll(response.servers); servers.addAll(response.result.servers);
room = matrix.client.getRoomById(roomId); room = matrix.client.getRoomById(roomId);
} }
} }
@ -81,21 +82,22 @@ class UrlLauncher {
} }
if (roomIdOrAlias.sigil == '!') { if (roomIdOrAlias.sigil == '!') {
roomId = roomIdOrAlias; roomId = roomIdOrAlias;
final response = final response = await showFutureLoadingDialog(
await SimpleDialogs(context).tryRequestWithLoadingDialog( context: context,
matrix.client.joinRoomOrAlias( future: () => matrix.client.joinRoomOrAlias(
roomIdOrAlias, roomIdOrAlias,
servers: servers.isNotEmpty ? servers.toList() : null, servers: servers.isNotEmpty ? servers.toList() : null,
), ),
); );
if (response == false) return; if (response.error != null) return;
// wait for two seconds so that it probably came down /sync // wait for two seconds so that it probably came down /sync
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
Future.delayed(const Duration(seconds: 2))); context: context,
future: () => Future.delayed(const Duration(seconds: 2)));
await Navigator.pushAndRemoveUntil( await Navigator.pushAndRemoveUntil(
context, context,
AppRoute.defaultRoute( AppRoute.defaultRoute(
context, ChatView(response, scrollToEventId: event)), context, ChatView(response.result, scrollToEventId: event)),
(r) => r.isFirst, (r) => r.isFirst,
); );
} else if (identifier.sigil == '#') { } else if (identifier.sigil == '#') {
@ -126,8 +128,11 @@ class UrlLauncher {
title: 'Message user $identifier', title: 'Message user $identifier',
) == ) ==
OkCancelResult.ok) { OkCancelResult.ok) {
roomId = await SimpleDialogs(context) roomId = (await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(user.startDirectChat()); context: context,
future: () => user.startDirectChat(),
))
.result;
Navigator.of(context).pop(); Navigator.of(context).pop();
if (roomId != null) { if (roomId != null) {

View File

@ -11,7 +11,7 @@ import 'package:fluffychat/components/avatar.dart';
import 'package:fluffychat/components/chat_settings_popup_menu.dart'; import 'package:fluffychat/components/chat_settings_popup_menu.dart';
import 'package:fluffychat/components/connection_status_header.dart'; import 'package:fluffychat/components/connection_status_header.dart';
import 'package:fluffychat/components/dialogs/recording_dialog.dart'; import 'package:fluffychat/components/dialogs/recording_dialog.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/encryption_button.dart'; import 'package:fluffychat/components/encryption_button.dart';
import 'package:fluffychat/components/list_items/message.dart'; import 'package:fluffychat/components/list_items/message.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
@ -114,8 +114,9 @@ class _ChatState extends State<_Chat> {
if (_canLoadMore) { if (_canLoadMore) {
setState(() => _loadingHistory = true); setState(() => _loadingHistory = true);
await SimpleDialogs(context).tryRequestWithErrorToast( await showFutureLoadingDialog(
timeline.requestHistory(historyCount: _loadHistoryCount), context: context,
future: () => timeline.requestHistory(historyCount: _loadHistoryCount),
); );
// we do NOT setState() here as then the event order will be wrong. // we do NOT setState() here as then the event order will be wrong.
@ -275,8 +276,9 @@ class _ChatState extends State<_Chat> {
final audioFile = File(result); final audioFile = File(result);
// as we already explicitly say send in the recording dialog, // as we already explicitly say send in the recording dialog,
// we do not need the send file dialog anymore. We can just send this straight away. // we do not need the send file dialog anymore. We can just send this straight away.
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
room.sendFileEvent( context: context,
future: () => room.sendFileEvent(
MatrixAudioFile( MatrixAudioFile(
bytes: audioFile.readAsBytesSync(), name: audioFile.path), bytes: audioFile.readAsBytesSync(), name: audioFile.path),
), ),
@ -313,8 +315,9 @@ class _ChatState extends State<_Chat> {
OkCancelResult.ok; OkCancelResult.ok;
if (!confirmed) return; if (!confirmed) return;
for (var event in selectedEvents) { for (var event in selectedEvents) {
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
event.status > 0 ? event.redact() : event.remove()); context: context,
future: () => event.status > 0 ? event.redact() : event.remove());
} }
setState(() => selectedEvents.clear()); setState(() => selectedEvents.clear());
} }
@ -400,7 +403,7 @@ class _ChatState extends State<_Chat> {
} }
}); });
if (context != null) { if (context != null) {
await SimpleDialogs(context).tryRequestWithLoadingDialog(task); await showFutureLoadingDialog(context: context, future: () => task);
} else { } else {
await task; await task;
} }
@ -445,8 +448,9 @@ class _ChatState extends State<_Chat> {
} }
void _sendEmojiAction(BuildContext context, String emoji) { void _sendEmojiAction(BuildContext context, String emoji) {
SimpleDialogs(context).tryRequestWithLoadingDialog( showFutureLoadingDialog(
room.sendReaction( context: context,
future: () => room.sendReaction(
selectedEvents.first.eventId, selectedEvents.first.eventId,
emoji, emoji,
), ),
@ -472,7 +476,7 @@ class _ChatState extends State<_Chat> {
matrix.activeRoomId = widget.id; matrix.activeRoomId = widget.id;
if (room.membership == Membership.invite) { if (room.membership == Membership.invite) {
SimpleDialogs(context).tryRequestWithLoadingDialog(room.join()); showFutureLoadingDialog(context: context, future: () => room.join());
} }
final typingText = room.getLocalizedTypingText(context); final typingText = room.getLocalizedTypingText(context);

View File

@ -10,7 +10,7 @@ import 'package:file_picker_cross/file_picker_cross.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/chat_settings_popup_menu.dart'; import 'package:fluffychat/components/chat_settings_popup_menu.dart';
import 'package:fluffychat/components/content_banner.dart'; import 'package:fluffychat/components/content_banner.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/list_items/participant_list_item.dart'; import 'package:fluffychat/components/list_items/participant_list_item.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/matrix_locals.dart'; import 'package:fluffychat/utils/matrix_locals.dart';
@ -52,10 +52,11 @@ class _ChatDetailsState extends State<ChatDetails> {
], ],
); );
if (input == null) return; if (input == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
widget.room.setName(input.single), context: context,
future: () => widget.room.setName(input.single),
); );
if (success != false) { if (success.error == null) {
await FlushbarHelper.createSuccess( await FlushbarHelper.createSuccess(
message: L10n.of(context).displaynameHasBeenChanged) message: L10n.of(context).displaynameHasBeenChanged)
.show(context); .show(context);
@ -82,19 +83,24 @@ class _ChatDetailsState extends State<ChatDetails> {
if (aliases.indexWhere((s) => s == canonicalAlias) == -1) { if (aliases.indexWhere((s) => s == canonicalAlias) == -1) {
var newAliases = List<String>.from(aliases); var newAliases = List<String>.from(aliases);
newAliases.add(canonicalAlias); newAliases.add(canonicalAlias);
final response = await SimpleDialogs(context).tryRequestWithLoadingDialog( final response = await showFutureLoadingDialog(
widget.room.client.requestRoomAliasInformations(canonicalAlias), context: context,
future: () =>
widget.room.client.requestRoomAliasInformations(canonicalAlias),
); );
if (response == false) { if (response.error != null) {
final success = final success = await showFutureLoadingDialog(
await SimpleDialogs(context).tryRequestWithLoadingDialog( context: context,
widget.room.client.createRoomAlias(canonicalAlias, widget.room.id), future: () => widget.room.client
.createRoomAlias(canonicalAlias, widget.room.id),
); );
if (success == false) return; if (success.error != null) return;
} }
} }
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
widget.room.client.sendState(widget.room.id, 'm.room.canonical_alias', { context: context,
future: () => widget.room.client
.sendState(widget.room.id, 'm.room.canonical_alias', {
'alias': input.single, 'alias': input.single,
}), }),
); );
@ -114,10 +120,11 @@ class _ChatDetailsState extends State<ChatDetails> {
], ],
); );
if (input == null) return; if (input == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
widget.room.setDescription(input.single), context: context,
future: () => widget.room.setDescription(input.single),
); );
if (success != false) { if (success.error == null) {
await FlushbarHelper.createSuccess( await FlushbarHelper.createSuccess(
message: L10n.of(context).groupDescriptionHasBeenChanged) message: L10n.of(context).groupDescriptionHasBeenChanged)
.show(context); .show(context);
@ -148,10 +155,11 @@ class _ChatDetailsState extends State<ChatDetails> {
); );
} }
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
widget.room.setAvatar(file), context: context,
future: () => widget.room.setAvatar(file),
); );
if (success != false) { if (success.error == null) {
await FlushbarHelper.createSuccess( await FlushbarHelper.createSuccess(
message: L10n.of(context).avatarHasBeenChanged) message: L10n.of(context).avatarHasBeenChanged)
.show(context); .show(context);
@ -159,9 +167,11 @@ class _ChatDetailsState extends State<ChatDetails> {
} }
void requestMoreMembersAction(BuildContext context) async { void requestMoreMembersAction(BuildContext context) async {
final List<User> participants = await SimpleDialogs(context) final participants = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(widget.room.requestParticipants()); context: context, future: () => widget.room.requestParticipants());
if (participants != null) setState(() => members = participants); if (participants.error == null) {
setState(() => members = participants.result);
}
} }
@override @override
@ -359,9 +369,10 @@ class _ChatDetailsState extends State<ChatDetails> {
), ),
), ),
onSelected: (JoinRules joinRule) => onSelected: (JoinRules joinRule) =>
SimpleDialogs(context) showFutureLoadingDialog(
.tryRequestWithLoadingDialog( context: context,
widget.room.setJoinRules(joinRule), future: () =>
widget.room.setJoinRules(joinRule),
), ),
itemBuilder: (BuildContext context) => itemBuilder: (BuildContext context) =>
<PopupMenuEntry<JoinRules>>[ <PopupMenuEntry<JoinRules>>[
@ -399,9 +410,9 @@ class _ChatDetailsState extends State<ChatDetails> {
), ),
onSelected: onSelected:
(HistoryVisibility historyVisibility) => (HistoryVisibility historyVisibility) =>
SimpleDialogs(context) showFutureLoadingDialog(
.tryRequestWithLoadingDialog( context: context,
widget.room future: () => widget.room
.setHistoryVisibility(historyVisibility), .setHistoryVisibility(historyVisibility),
), ),
itemBuilder: (BuildContext context) => itemBuilder: (BuildContext context) =>
@ -453,9 +464,10 @@ class _ChatDetailsState extends State<ChatDetails> {
), ),
), ),
onSelected: (GuestAccess guestAccess) => onSelected: (GuestAccess guestAccess) =>
SimpleDialogs(context) showFutureLoadingDialog(
.tryRequestWithLoadingDialog( context: context,
widget.room.setGuestAccess(guestAccess), future: () =>
widget.room.setGuestAccess(guestAccess),
), ),
itemBuilder: (BuildContext context) => itemBuilder: (BuildContext context) =>
<PopupMenuEntry<GuestAccess>>[ <PopupMenuEntry<GuestAccess>>[

View File

@ -6,7 +6,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/connection_status_header.dart'; import 'package:fluffychat/components/connection_status_header.dart';
import 'package:fluffychat/components/default_app_bar_search_field.dart'; import 'package:fluffychat/components/default_app_bar_search_field.dart';
import 'package:fluffychat/components/default_drawer.dart'; import 'package:fluffychat/components/default_drawer.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/app_config.dart'; import 'package:fluffychat/app_config.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -142,24 +142,28 @@ class _ChatListState extends State<ChatList> {
Future<void> _toggleUnread(BuildContext context) { Future<void> _toggleUnread(BuildContext context) {
final room = Matrix.of(context).client.getRoomById(_selectedRoomIds.single); final room = Matrix.of(context).client.getRoomById(_selectedRoomIds.single);
return SimpleDialogs(context).tryRequestWithLoadingDialog( return showFutureLoadingDialog(
room.setUnread(!room.isUnread), context: context,
future: () => room.setUnread(!room.isUnread),
); );
} }
Future<void> _toggleFavouriteRoom(BuildContext context) { Future<void> _toggleFavouriteRoom(BuildContext context) {
final room = Matrix.of(context).client.getRoomById(_selectedRoomIds.single); final room = Matrix.of(context).client.getRoomById(_selectedRoomIds.single);
return SimpleDialogs(context).tryRequestWithLoadingDialog( return showFutureLoadingDialog(
room.setFavourite(!room.isFavourite), context: context,
future: () => room.setFavourite(!room.isFavourite),
); );
} }
Future<void> _toggleMuted(BuildContext context) { Future<void> _toggleMuted(BuildContext context) {
final room = Matrix.of(context).client.getRoomById(_selectedRoomIds.single); final room = Matrix.of(context).client.getRoomById(_selectedRoomIds.single);
return SimpleDialogs(context).tryRequestWithLoadingDialog( return showFutureLoadingDialog(
room.setPushRuleState(room.pushRuleState == PushRuleState.notify context: context,
? PushRuleState.mentions_only future: () => room.setPushRuleState(
: PushRuleState.notify), room.pushRuleState == PushRuleState.notify
? PushRuleState.mentions_only
: PushRuleState.notify),
); );
} }
@ -170,8 +174,10 @@ class _ChatListState extends State<ChatList> {
) == ) ==
OkCancelResult.ok; OkCancelResult.ok;
if (!confirmed) return; if (!confirmed) return;
await SimpleDialogs(context) await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(_archiveSelectedRooms(context)); context: context,
future: () => _archiveSelectedRooms(context),
);
setState(() => null); setState(() => null);
} }

View File

@ -2,7 +2,7 @@ import 'dart:developer';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/dialogs/permission_slider_dialog.dart'; import 'package:fluffychat/components/dialogs/permission_slider_dialog.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:flushbar/flushbar_helper.dart'; import 'package:flushbar/flushbar_helper.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -55,8 +55,10 @@ class ChatPermissionsSettings extends StatelessWidget {
content[key] = newLevel; content[key] = newLevel;
} }
inspect(content); inspect(content);
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
room.client.sendState(room.id, EventTypes.RoomPowerLevels, content), context: context,
future: () =>
room.client.sendState(room.id, EventTypes.RoomPowerLevels, content),
); );
} }

View File

@ -5,7 +5,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/avatar.dart'; import 'package:fluffychat/components/avatar.dart';
import 'package:fluffychat/components/default_app_bar_search_field.dart'; import 'package:fluffychat/components/default_app_bar_search_field.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart'; import 'package:fluffychat/views/chat.dart';
@ -101,18 +101,19 @@ class _DiscoverPageState extends State<DiscoverPage> {
OkCancelResult.cancel) { OkCancelResult.cancel) {
return; return;
} }
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
_joinRoomAndWait( context: context,
future: () => _joinRoomAndWait(
context, context,
room.roomId, room.roomId,
room.canonicalAlias ?? room.aliases.first, room.canonicalAlias ?? room.aliases.first,
), ),
); );
if (success != false) { if (success.error == null) {
await Navigator.of(context).push( await Navigator.of(context).push(
AppRoute.defaultRoute( AppRoute.defaultRoute(
context, context,
ChatView(success), ChatView(success.result),
), ),
); );
} }

View File

@ -2,7 +2,7 @@ import 'dart:math';
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/app_config.dart'; import 'package:fluffychat/app_config.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -41,9 +41,10 @@ class HomeserverPicker extends StatelessWidget {
homeserver = 'https://$homeserver'; homeserver = 'https://$homeserver';
} }
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
checkHomeserver(homeserver, Matrix.of(context).client)); context: context,
if (success == true) { future: () => checkHomeserver(homeserver, Matrix.of(context).client));
if (success.result == true) {
await Navigator.of(context) await Navigator.of(context)
.push(AppRoute(AppConfig.enableRegistration ? SignUp() : Login())); .push(AppRoute(AppConfig.enableRegistration ? SignUp() : Login()));
} }

View File

@ -6,11 +6,12 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/matrix_api.dart'; import 'package:famedlysdk/matrix_api.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/avatar.dart'; import 'package:fluffychat/components/avatar.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../utils/localized_exception_extension.dart';
import 'chat_list.dart'; import 'chat_list.dart';
class InvitationSelection extends StatefulWidget { class InvitationSelection extends StatefulWidget {
@ -57,10 +58,11 @@ class _InvitationSelectionState extends State<InvitationSelection> {
} }
void inviteAction(BuildContext context, String id) async { void inviteAction(BuildContext context, String id) async {
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
widget.room.invite(id), context: context,
future: () => widget.room.invite(id),
); );
if (success != false) { if (success.error == null) {
await FlushbarHelper.createSuccess( await FlushbarHelper.createSuccess(
message: L10n.of(context).contactHasBeenInvitedToTheGroup) message: L10n.of(context).contactHasBeenInvitedToTheGroup)
.show(context); .show(context);
@ -87,11 +89,16 @@ class _InvitationSelectionState extends State<InvitationSelection> {
if (loading) return; if (loading) return;
setState(() => loading = true); setState(() => loading = true);
final matrix = Matrix.of(context); final matrix = Matrix.of(context);
final response = await SimpleDialogs(context).tryRequestWithErrorToast( UserSearchResult response;
matrix.client.searchUser(text, limit: 10), try {
); response = await matrix.client.searchUser(text, limit: 10);
setState(() => loading = false); } catch (e) {
if (response == false || (response?.results == null)) return; FlushbarHelper.createError(
message: (e as Object).toLocalizedString(context));
return;
} finally {
setState(() => loading = false);
}
setState(() { setState(() {
foundProfiles = List<Profile>.from(response.results); foundProfiles = List<Profile>.from(response.results);
if ('@$text'.isValidMatrixId && if ('@$text'.isValidMatrixId &&

View File

@ -3,7 +3,7 @@ import 'dart:math';
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/firebase_controller.dart'; import 'package:fluffychat/utils/firebase_controller.dart';
@ -87,8 +87,10 @@ class _LoginState extends State<Login> {
final newDomain = wellKnownInformations.mHomeserver?.baseUrl; final newDomain = wellKnownInformations.mHomeserver?.baseUrl;
if ((newDomain?.isNotEmpty ?? false) && if ((newDomain?.isNotEmpty ?? false) &&
newDomain != Matrix.of(context).client.homeserver.toString()) { newDomain != Matrix.of(context).client.homeserver.toString()) {
await SimpleDialogs(context).tryRequestWithErrorToast( await showFutureLoadingDialog(
Matrix.of(context).client.checkHomeserver(newDomain)); context: context,
future: () => Matrix.of(context).client.checkHomeserver(newDomain),
);
setState(() => usernameError = null); setState(() => usernameError = null);
} }
} catch (e) { } catch (e) {
@ -109,14 +111,15 @@ class _LoginState extends State<Login> {
); );
if (input == null) return; if (input == null) return;
final clientSecret = DateTime.now().millisecondsSinceEpoch.toString(); final clientSecret = DateTime.now().millisecondsSinceEpoch.toString();
final response = await SimpleDialogs(context).tryRequestWithLoadingDialog( final response = await showFutureLoadingDialog(
Matrix.of(context).client.resetPasswordUsingEmail( context: context,
future: () => Matrix.of(context).client.resetPasswordUsingEmail(
input.single, input.single,
clientSecret, clientSecret,
sendAttempt++, sendAttempt++,
), ),
); );
if (response == false) return; if (response.error != null) return;
final ok = await showOkAlertDialog( final ok = await showOkAlertDialog(
context: context, context: context,
title: L10n.of(context).weSentYouAnEmail, title: L10n.of(context).weSentYouAnEmail,
@ -137,8 +140,9 @@ class _LoginState extends State<Login> {
], ],
); );
if (password == null) return; if (password == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
Matrix.of(context).client.changePassword( context: context,
future: () => Matrix.of(context).client.changePassword(
password.single, password.single,
auth: AuthenticationThreePidCreds( auth: AuthenticationThreePidCreds(
type: AuthenticationTypes.emailIdentity, type: AuthenticationTypes.emailIdentity,
@ -151,7 +155,7 @@ class _LoginState extends State<Login> {
), ),
), ),
); );
if (success != false) { if (success.error == null) {
FlushbarHelper.createSuccess( FlushbarHelper.createSuccess(
message: L10n.of(context).passwordHasBeenChanged); message: L10n.of(context).passwordHasBeenChanged);
} }

View File

@ -1,6 +1,6 @@
import 'package:famedlysdk/matrix_api.dart' as api; import 'package:famedlysdk/matrix_api.dart' as api;
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -33,9 +33,9 @@ class _NewGroupState extends State<_NewGroup> {
void submitAction(BuildContext context) async { void submitAction(BuildContext context) async {
final matrix = Matrix.of(context); final matrix = Matrix.of(context);
final String roomID = final roomID = await showFutureLoadingDialog(
await SimpleDialogs(context).tryRequestWithLoadingDialog( context: context,
matrix.client.createRoom( future: () => matrix.client.createRoom(
preset: publicGroup preset: publicGroup
? api.CreateRoomPreset.public_chat ? api.CreateRoomPreset.public_chat
: api.CreateRoomPreset.private_chat, : api.CreateRoomPreset.private_chat,
@ -51,7 +51,7 @@ class _NewGroupState extends State<_NewGroup> {
Navigator.of(context).push( Navigator.of(context).push(
AppRoute.defaultRoute( AppRoute.defaultRoute(
context, context,
ChatView(roomID), ChatView(roomID.result),
), ),
), ),
); );
@ -59,7 +59,7 @@ class _NewGroupState extends State<_NewGroup> {
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => InvitationSelection( builder: (context) => InvitationSelection(
matrix.client.getRoomById(roomID), matrix.client.getRoomById(roomID.result),
), ),
), ),
); );

View File

@ -4,7 +4,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/matrix_api.dart'; import 'package:famedlysdk/matrix_api.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/avatar.dart'; import 'package:fluffychat/components/avatar.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/fluffy_share.dart'; import 'package:fluffychat/utils/fluffy_share.dart';
@ -56,15 +56,17 @@ class _NewPrivateChatState extends State<_NewPrivateChat> {
'@' + controller.text.trim(), '@' + controller.text.trim(),
room: Room(id: '', client: matrix.client), room: Room(id: '', client: matrix.client),
); );
final String roomID = await SimpleDialogs(context) final roomID = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(user.startDirectChat()); context: context,
future: () => user.startDirectChat(),
);
Navigator.of(context).pop(); Navigator.of(context).pop();
if (roomID != null) { if (roomID.error == null) {
await Navigator.of(context).push( await Navigator.of(context).push(
AppRoute.defaultRoute( AppRoute.defaultRoute(
context, context,
ChatView(roomID), ChatView(roomID.result),
), ),
); );
} }
@ -89,13 +91,14 @@ class _NewPrivateChatState extends State<_NewPrivateChat> {
if (loading) return; if (loading) return;
setState(() => loading = true); setState(() => loading = true);
final matrix = Matrix.of(context); final matrix = Matrix.of(context);
final response = await SimpleDialogs(context).tryRequestWithErrorToast( final response = await showFutureLoadingDialog(
matrix.client.searchUser(text, limit: 10), context: context,
future: () => matrix.client.searchUser(text, limit: 10),
); );
setState(() => loading = false); setState(() => loading = false);
if (response == false || (response?.results?.isEmpty ?? true)) return; if (response.result?.results?.isEmpty ?? true) return;
setState(() { setState(() {
foundProfiles = List<Profile>.from(response.results); foundProfiles = List<Profile>.from(response.result.results);
}); });
} }

View File

@ -21,7 +21,7 @@ import 'package:url_launcher/url_launcher.dart';
import '../components/adaptive_page_layout.dart'; import '../components/adaptive_page_layout.dart';
import '../components/content_banner.dart'; import '../components/content_banner.dart';
import '../components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import '../components/matrix.dart'; import '../components/matrix.dart';
import '../utils/app_route.dart'; import '../utils/app_route.dart';
import '../app_config.dart'; import '../app_config.dart';
@ -62,8 +62,10 @@ class _SettingsState extends State<Settings> {
return; return;
} }
var matrix = Matrix.of(context); var matrix = Matrix.of(context);
await SimpleDialogs(context) await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(matrix.client.logout()); context: context,
future: () => matrix.client.logout(),
);
} }
void _changePasswordAccountAction(BuildContext context) async { void _changePasswordAccountAction(BuildContext context) async {
@ -86,8 +88,9 @@ class _SettingsState extends State<Settings> {
], ],
); );
if (input == null) return; if (input == null) return;
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
Matrix.of(context) context: context,
future: () => Matrix.of(context)
.client .client
.changePassword(input.last, oldPassword: input.first), .changePassword(input.last, oldPassword: input.first),
); );
@ -123,8 +126,9 @@ class _SettingsState extends State<Settings> {
], ],
); );
if (input == null) return; if (input == null) return;
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
Matrix.of(context).client.deactivateAccount( context: context,
future: () => Matrix.of(context).client.deactivateAccount(
auth: AuthenticationPassword( auth: AuthenticationPassword(
password: input.single, password: input.single,
user: Matrix.of(context).client.userID, user: Matrix.of(context).client.userID,
@ -170,10 +174,12 @@ class _SettingsState extends State<Settings> {
); );
if (input == null) return; if (input == null) return;
final matrix = Matrix.of(context); final matrix = Matrix.of(context);
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
matrix.client.setDisplayname(matrix.client.userID, input.single), context: context,
future: () =>
matrix.client.setDisplayname(matrix.client.userID, input.single),
); );
if (success != false) { if (success.error == null) {
setState(() { setState(() {
profileFuture = null; profileFuture = null;
profile = null; profile = null;
@ -204,10 +210,11 @@ class _SettingsState extends State<Settings> {
); );
} }
final matrix = Matrix.of(context); final matrix = Matrix.of(context);
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
matrix.client.setAvatar(file), context: context,
future: () => matrix.client.setAvatar(file),
); );
if (success != false) { if (success.error == null) {
setState(() { setState(() {
profileFuture = null; profileFuture = null;
profile = null; profile = null;
@ -230,21 +237,22 @@ class _SettingsState extends State<Settings> {
], ],
); );
if (input != null) { if (input != null) {
final valid = await SimpleDialogs(context) final valid = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(Future.microtask(() async { context: context,
// make sure the loading spinner shows before we test the keys future: () async {
await Future.delayed(Duration(milliseconds: 100)); // make sure the loading spinner shows before we test the keys
var valid = false; await Future.delayed(Duration(milliseconds: 100));
try { var valid = false;
await handle.unlock(recoveryKey: input.single); try {
valid = true; await handle.unlock(recoveryKey: input.single);
} catch (e, s) { valid = true;
SentryController.captureException(e, s); } catch (e, s) {
} SentryController.captureException(e, s);
return valid; }
})); return valid;
});
if (valid == true) { if (valid.result == true) {
await handle.maybeCacheAll(); await handle.maybeCacheAll();
await showOkAlertDialog( await showOkAlertDialog(
context: context, context: context,
@ -514,28 +522,29 @@ class _SettingsState extends State<Settings> {
], ],
); );
if (input != null) { if (input != null) {
final valid = await SimpleDialogs(context) final valid = await showFutureLoadingDialog(
.tryRequestWithLoadingDialog(Future.microtask(() async { context: context,
// make sure the loading spinner shows before we test the keys future: () async {
await Future.delayed(Duration(milliseconds: 100)); // make sure the loading spinner shows before we test the keys
var valid = false; await Future.delayed(Duration(milliseconds: 100));
try { var valid = false;
await client.encryption.crossSigning try {
.selfSign(recoveryKey: input.single); await client.encryption.crossSigning
valid = true; .selfSign(recoveryKey: input.single);
} catch (_) { valid = true;
try { } catch (_) {
await client.encryption.crossSigning try {
.selfSign(passphrase: input.single); await client.encryption.crossSigning
valid = true; .selfSign(passphrase: input.single);
} catch (_) { valid = true;
valid = false; } catch (_) {
} valid = false;
} }
return valid; }
})); return valid;
});
if (valid == true) { if (valid.result == true) {
await showOkAlertDialog( await showOkAlertDialog(
context: context, context: context,
message: L10n.of(context).verifiedSession, message: L10n.of(context).verifiedSession,

View File

@ -1,7 +1,7 @@
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -40,14 +40,15 @@ class _Settings3PidState extends State<Settings3Pid> {
); );
if (input == null) return; if (input == null) return;
final clientSecret = DateTime.now().millisecondsSinceEpoch.toString(); final clientSecret = DateTime.now().millisecondsSinceEpoch.toString();
final response = await SimpleDialogs(context).tryRequestWithLoadingDialog( final response = await showFutureLoadingDialog(
Matrix.of(context).client.requestEmailToken( context: context,
future: () => Matrix.of(context).client.requestEmailToken(
input.single, input.single,
clientSecret, clientSecret,
Settings3Pid.sendAttempt++, Settings3Pid.sendAttempt++,
), ),
); );
if (response == false) return; if (response.error != null) return;
final ok = await showOkAlertDialog( final ok = await showOkAlertDialog(
context: context, context: context,
title: L10n.of(context).weSentYouAnEmail, title: L10n.of(context).weSentYouAnEmail,
@ -68,8 +69,9 @@ class _Settings3PidState extends State<Settings3Pid> {
], ],
); );
if (password == null) return; if (password == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
Matrix.of(context).client.uiaRequestBackground( context: context,
future: () => Matrix.of(context).client.uiaRequestBackground(
(auth) => Matrix.of(context).client.addThirdPartyIdentifier( (auth) => Matrix.of(context).client.addThirdPartyIdentifier(
clientSecret, clientSecret,
(response as RequestTokenResponse).sid, (response as RequestTokenResponse).sid,
@ -77,7 +79,7 @@ class _Settings3PidState extends State<Settings3Pid> {
), ),
), ),
); );
if (success == false) return; if (success.error != null) return;
setState(() => _request = null); setState(() => _request = null);
} }
@ -92,12 +94,13 @@ class _Settings3PidState extends State<Settings3Pid> {
OkCancelResult.ok) { OkCancelResult.ok) {
return; return;
} }
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
Matrix.of(context).client.deleteThirdPartyIdentifier( context: context,
future: () => Matrix.of(context).client.deleteThirdPartyIdentifier(
identifier.address, identifier.address,
identifier.medium, identifier.medium,
)); ));
if (success == false) return; if (success.error != null) return;
setState(() => _request = null); setState(() => _request = null);
} }

View File

@ -1,6 +1,6 @@
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -60,8 +60,9 @@ class DevicesSettingsState extends State<DevicesSettings> {
); );
if (password == null) return; if (password == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
matrix.client.deleteDevices( context: context,
future: () => matrix.client.deleteDevices(
deviceIds, deviceIds,
auth: AuthenticationPassword( auth: AuthenticationPassword(
password: password.single, password: password.single,
@ -70,7 +71,7 @@ class DevicesSettingsState extends State<DevicesSettings> {
), ),
), ),
); );
if (success != false) { if (success.error == null) {
reload(); reload();
} }
} }
@ -86,12 +87,13 @@ class DevicesSettingsState extends State<DevicesSettings> {
], ],
); );
if (displayName == null) return; if (displayName == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await showFutureLoadingDialog(
Matrix.of(context) context: context,
future: () => Matrix.of(context)
.client .client
.setDeviceMetadata(device.deviceId, displayName: displayName.single), .setDeviceMetadata(device.deviceId, displayName: displayName.single),
); );
if (success != false) { if (success.error == null) {
reload(); reload();
} }
} }

View File

@ -11,7 +11,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import '../components/adaptive_page_layout.dart'; import '../components/adaptive_page_layout.dart';
import '../components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import '../components/matrix.dart'; import '../components/matrix.dart';
import 'chat_list.dart'; import 'chat_list.dart';
@ -94,13 +94,16 @@ class _EmotesSettingsState extends State<EmotesSettings> {
// remove the old "short" key // remove the old "short" key
content.remove('short'); content.remove('short');
if (widget.room != null) { if (widget.room != null) {
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
client.sendState(widget.room.id, 'im.ponies.room_emotes', content, context: context,
widget.stateKey ?? ''), future: () => client.sendState(widget.room.id, 'im.ponies.room_emotes',
content, widget.stateKey ?? ''),
); );
} else { } else {
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
client.setAccountData(client.userID, 'im.ponies.user_emotes', content), context: context,
future: () => client.setAccountData(
client.userID, 'im.ponies.user_emotes', content),
); );
} }
} }
@ -128,8 +131,10 @@ class _EmotesSettingsState extends State<EmotesSettings> {
content['rooms'][widget.room.id].remove(widget.stateKey ?? ''); content['rooms'][widget.room.id].remove(widget.stateKey ?? '');
} }
// and save // and save
await SimpleDialogs(context).tryRequestWithLoadingDialog( await showFutureLoadingDialog(
client.setAccountData(client.userID, 'im.ponies.emote_rooms', content), context: context,
future: () => client.setAccountData(
client.userID, 'im.ponies.emote_rooms', content),
); );
} }
@ -477,13 +482,16 @@ class _EmoteImagePickerState extends State<_EmoteImagePicker> {
name: result.fileName, name: result.fileName,
); );
} }
final uploadResp = final uploadResp = await showFutureLoadingDialog(
await SimpleDialogs(context).tryRequestWithLoadingDialog( context: context,
Matrix.of(context).client.upload(file.bytes, file.name), future: () =>
Matrix.of(context).client.upload(file.bytes, file.name),
); );
setState(() { if (uploadResp.error == null) {
widget.controller.text = uploadResp; setState(() {
}); widget.controller.text = uploadResp.result;
});
}
}, },
); );
} else { } else {

View File

@ -1,7 +1,7 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/avatar.dart'; import 'package:fluffychat/components/avatar.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -24,8 +24,9 @@ class SettingsIgnoreList extends StatelessWidget {
void _ignoreUser(BuildContext context) { void _ignoreUser(BuildContext context) {
if (controller.text.isEmpty) return; if (controller.text.isEmpty) return;
SimpleDialogs(context).tryRequestWithLoadingDialog( showFutureLoadingDialog(
Matrix.of(context).client.ignoreUser('@${controller.text}'), context: context,
future: () => Matrix.of(context).client.ignoreUser('@${controller.text}'),
); );
controller.clear(); controller.clear();
} }
@ -86,9 +87,10 @@ class SettingsIgnoreList extends StatelessWidget {
Text(s.data?.displayname ?? client.ignoredUsers[i]), Text(s.data?.displayname ?? client.ignoredUsers[i]),
trailing: IconButton( trailing: IconButton(
icon: Icon(Icons.delete_forever_outlined), icon: Icon(Icons.delete_forever_outlined),
onPressed: () => SimpleDialogs(context) onPressed: () => showFutureLoadingDialog(
.tryRequestWithLoadingDialog( context: context,
client.unignoreUser(client.ignoredUsers[i]), future: () =>
client.unignoreUser(client.ignoredUsers[i]),
), ),
), ),
), ),

View File

@ -2,7 +2,7 @@ import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/app_config.dart'; import 'package:fluffychat/app_config.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -107,8 +107,9 @@ class SettingsNotifications extends StatelessWidget {
void _setNotificationSetting( void _setNotificationSetting(
BuildContext context, NotificationSettingsItem item, bool enabled) { BuildContext context, NotificationSettingsItem item, bool enabled) {
SimpleDialogs(context).tryRequestWithLoadingDialog( showFutureLoadingDialog(
Matrix.of(context).client.enablePushRule( context: context,
future: () => Matrix.of(context).client.enablePushRule(
'global', 'global',
item.type, item.type,
item.key, item.key,
@ -136,9 +137,11 @@ class SettingsNotifications extends StatelessWidget {
value: !Matrix.of(context).client.allPushNotificationsMuted, value: !Matrix.of(context).client.allPushNotificationsMuted,
title: title:
Text(L10n.of(context).notificationsEnabledForThisAccount), Text(L10n.of(context).notificationsEnabledForThisAccount),
onChanged: (_) => onChanged: (_) => showFutureLoadingDialog(
SimpleDialogs(context).tryRequestWithLoadingDialog( context: context,
Matrix.of(context).client.setMuteAllPushNotifications( future: () => Matrix.of(context)
.client
.setMuteAllPushNotifications(
!Matrix.of(context).client.allPushNotificationsMuted, !Matrix.of(context).client.allPushNotificationsMuted,
), ),
), ),

View File

@ -429,6 +429,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
future_loading_dialog:
dependency: "direct main"
description:
name: future_loading_dialog
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
glob: glob:
dependency: transitive dependency: transitive
description: description:

View File

@ -64,6 +64,7 @@ dependencies:
flutter_cache_manager: ^2.1.0 flutter_cache_manager: ^2.1.0
open_noti_settings: ^0.0.4 open_noti_settings: ^0.0.4
emoji_picker: ^0.1.0 emoji_picker: ^0.1.0
future_loading_dialog: ^0.1.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: