From 820e79593c169d7223100f2b7da8fcb049ea059b Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:58:48 -0500 Subject: [PATCH] fix: wait for bot options to be saved before closing conversation bot dialog (#1868) --- .../conversation_bot_settings.dart | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/pangea/chat_settings/widgets/conversation_bot/conversation_bot_settings.dart b/lib/pangea/chat_settings/widgets/conversation_bot/conversation_bot_settings.dart index d13df377f..87a10cd55 100644 --- a/lib/pangea/chat_settings/widgets/conversation_bot/conversation_bot_settings.dart +++ b/lib/pangea/chat_settings/widgets/conversation_bot/conversation_bot_settings.dart @@ -18,6 +18,7 @@ import 'package:fluffychat/pangea/common/widgets/full_width_dialog.dart'; import 'package:fluffychat/pangea/events/constants/pangea_event_types.dart'; import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart'; import 'package:fluffychat/pangea/learning_settings/enums/language_level_type_enum.dart'; +import 'package:fluffychat/widgets/future_loading_dialog.dart'; import 'package:fluffychat/widgets/matrix.dart'; class ConversationBotSettings extends StatefulWidget { @@ -54,18 +55,6 @@ class ConversationBotSettingsState extends State { } } - Future showBotOptionsDialog() async { - final BotOptionsModel? newBotOptions = await showDialog( - context: context, - builder: (BuildContext context) => - ConversationBotSettingsDialog(room: widget.room), - ); - - if (newBotOptions != null) { - setBotOptions(newBotOptions); - } - } - @override Widget build(BuildContext context) { return AnimatedContainer( @@ -91,7 +80,13 @@ class ConversationBotSettingsState extends State { expression: BotExpression.idle, ), ), - onTap: showBotOptionsDialog, + onTap: () => showDialog( + context: context, + builder: (BuildContext context) => ConversationBotSettingsDialog( + room: widget.room, + onSubmit: setBotOptions, + ), + ), ), ], ), @@ -101,10 +96,12 @@ class ConversationBotSettingsState extends State { class ConversationBotSettingsDialog extends StatefulWidget { final Room room; + final Function(BotOptionsModel) onSubmit; const ConversationBotSettingsDialog({ super.key, required this.room, + required this.onSubmit, }); @override @@ -272,7 +269,10 @@ class ConversationBotSettingsDialogState botOptions.targetLanguage ??= MatrixState .pangeaController.languageController.userL2?.langCode; - Navigator.of(context).pop(botOptions); + await showFutureLoadingDialog( + context: context, + future: () async => widget.onSubmit(botOptions), + ); final bool isBotRoomMember = await widget.room.botIsInRoom; if (addBot && !isBotRoomMember) { @@ -280,6 +280,8 @@ class ConversationBotSettingsDialogState } else if (!addBot && isBotRoomMember) { await widget.room.kick(BotName.byEnvironment); } + + Navigator.of(context).pop(botOptions); }, child: hasPermission ? Text(L10n.of(context).confirm)