From 975fb1a45cae95b34560b57679300f5fde4bb9ee Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Wed, 13 May 2020 10:45:50 +0200 Subject: [PATCH] Fix StyledToast --- lib/components/dialogs/simple_dialogs.dart | 8 +- lib/components/encryption_button.dart | 6 +- lib/components/list_items/chat_list_item.dart | 4 +- lib/main.dart | 78 +++++++++---------- lib/utils/firebase_controller.dart | 8 +- lib/views/chat.dart | 8 +- lib/views/chat_details.dart | 11 +-- lib/views/invitation_selection.dart | 4 +- lib/views/settings_emotes.dart | 4 +- lib/views/sign_up_password.dart | 6 +- pubspec.lock | 14 ++-- pubspec.yaml | 2 +- 12 files changed, 74 insertions(+), 79 deletions(-) diff --git a/lib/components/dialogs/simple_dialogs.dart b/lib/components/dialogs/simple_dialogs.dart index 48e315e..aecbdf1 100644 --- a/lib/components/dialogs/simple_dialogs.dart +++ b/lib/components/dialogs/simple_dialogs.dart @@ -1,7 +1,7 @@ import 'package:fluffychat/l10n/l10n.dart'; import 'package:flutter/material.dart'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; class SimpleDialogs { final BuildContext context; @@ -117,7 +117,7 @@ class SimpleDialogs { builder: (c) => AlertDialog( title: titleText != null ? Text(titleText) : null, content: contentText != null ? Text(contentText) : null, - actions: [ + actions: [ FlatButton( child: Text( okText ?? L10n.of(context).ok.toUpperCase(), @@ -149,10 +149,10 @@ class SimpleDialogs { onAdditionalAuth != null) { return await tryRequestWithErrorToast(onAdditionalAuth(exception)); } else { - showToast(exception.errorMessage); + BotToast.showText(text: exception.errorMessage); } } catch (exception) { - showToast(exception.toString()); + BotToast.showText(text: exception.toString()); return false; } } diff --git a/lib/components/encryption_button.dart b/lib/components/encryption_button.dart index e831568..3cd89de 100644 --- a/lib/components/encryption_button.dart +++ b/lib/components/encryption_button.dart @@ -5,7 +5,7 @@ import 'package:fluffychat/l10n/l10n.dart'; import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/views/chat_encryption_settings.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'dialogs/simple_dialogs.dart'; import 'matrix.dart'; @@ -22,7 +22,7 @@ class _EncryptionButtonState extends State { void _enableEncryptionAction() async { if (widget.room.encrypted) { - showToast(L10n.of(context).warningEncryptionInBeta); + BotToast.showText(text: L10n.of(context).warningEncryptionInBeta); await Navigator.of(context).push( AppRoute.defaultRoute( context, @@ -32,7 +32,7 @@ class _EncryptionButtonState extends State { return; } if (!widget.room.client.encryptionEnabled) { - showToast(L10n.of(context).needPantalaimonWarning); + BotToast.showText(text: L10n.of(context).needPantalaimonWarning); return; } if (await SimpleDialogs(context).askConfirmation( diff --git a/lib/components/list_items/chat_list_item.dart b/lib/components/list_items/chat_list_item.dart index 0227909..d900508 100644 --- a/lib/components/list_items/chat_list_item.dart +++ b/lib/components/list_items/chat_list_item.dart @@ -2,7 +2,7 @@ import 'package:famedlysdk/famedlysdk.dart'; import 'package:fluffychat/views/chat.dart'; import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:pedantic/pedantic.dart'; import '../../l10n/l10n.dart'; @@ -31,7 +31,7 @@ class ChatListItem extends StatelessWidget { } if (room.membership == Membership.ban) { - showToast(L10n.of(context).youHaveBeenBannedFromThisChat); + BotToast.showText(text: L10n.of(context).youHaveBeenBannedFromThisChat); return; } diff --git a/lib/main.dart b/lib/main.dart index a5675be..04cf0ec 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,7 +6,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'l10n/l10n.dart'; import 'components/theme_switcher.dart'; @@ -31,47 +31,41 @@ class App extends StatelessWidget { child: Builder( // Workaround for: https://github.com/JackJonson/flutter_styled_toast/issues/7 builder: (BuildContext context) => MaterialApp( - home: StyledToast( - duration: Duration(seconds: 5), - child: MaterialApp( - title: 'FluffyChat', - theme: ThemeSwitcherWidget.of(context).themeData, - localizationsDelegates: [ - AppLocalizationsDelegate(), - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: [ - const Locale('en'), // English - const Locale('de'), // German - const Locale('hu'), // Hungarian - const Locale('pl'), // Polish - ], - locale: kIsWeb - ? Locale(html.window.navigator.language.split("-").first) - : null, - home: FutureBuilder( - future: Matrix.of(context) - .client - .onLoginStateChanged - .stream - .first, - builder: (context, snapshot) { - if (!snapshot.hasData) { - return Scaffold( - body: Center( - child: CircularProgressIndicator(), - ), - ); - } - if (Matrix.of(context).client.isLogged()) { - return ChatListView(); - } - return HomeserverPicker(); - }, - ), - ), + title: 'FluffyChat', + builder: BotToastInit(), + navigatorObservers: [BotToastNavigatorObserver()], + theme: ThemeSwitcherWidget.of(context).themeData, + localizationsDelegates: [ + AppLocalizationsDelegate(), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: [ + const Locale('en'), // English + const Locale('de'), // German + const Locale('hu'), // Hungarian + const Locale('pl'), // Polish + ], + locale: kIsWeb + ? Locale(html.window.navigator.language.split("-").first) + : null, + home: FutureBuilder( + future: + Matrix.of(context).client.onLoginStateChanged.stream.first, + builder: (context, snapshot) { + if (!snapshot.hasData) { + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); + } + if (Matrix.of(context).client.isLogged()) { + return ChatListView(); + } + return HomeserverPicker(); + }, ), ), ), diff --git a/lib/utils/firebase_controller.dart b/lib/utils/firebase_controller.dart index 33427f2..d0991ca 100644 --- a/lib/utils/firebase_controller.dart +++ b/lib/utils/firebase_controller.dart @@ -9,7 +9,7 @@ import 'package:fluffychat/views/chat.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:path_provider/path_provider.dart'; import 'package:famedlysdk/famedlysdk.dart'; import 'famedlysdk_store.dart'; @@ -33,8 +33,8 @@ abstract class FirebaseController { token = null; } if (token?.isEmpty ?? true) { - showToast( - L10n.of(context).noGoogleServicesWarning, + BotToast.showText( + text: L10n.of(context).noGoogleServicesWarning, duration: Duration(seconds: 15), ); return; @@ -67,7 +67,7 @@ abstract class FirebaseController { ), (r) => r.isFirst); } catch (_) { - showToast("Failed to open chat..."); + BotToast.showText(text: "Failed to open chat..."); debugPrint(_); } }; diff --git a/lib/views/chat.dart b/lib/views/chat.dart index dacd8de..9f81649 100644 --- a/lib/views/chat.dart +++ b/lib/views/chat.dart @@ -15,7 +15,7 @@ import 'package:fluffychat/l10n/l10n.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:image_picker/image_picker.dart'; import 'package:pedantic/pedantic.dart'; @@ -177,7 +177,7 @@ class _ChatState extends State<_Chat> { void sendFileAction(BuildContext context) async { if (kIsWeb) { - showToast(L10n.of(context).notSupportedInWeb); + BotToast.showText(text: L10n.of(context).notSupportedInWeb); return; } File file = await FilePicker.getFile(); @@ -191,7 +191,7 @@ class _ChatState extends State<_Chat> { void sendImageAction(BuildContext context) async { if (kIsWeb) { - showToast(L10n.of(context).notSupportedInWeb); + BotToast.showText(text: L10n.of(context).notSupportedInWeb); return; } File file = await ImagePicker.pickImage( @@ -209,7 +209,7 @@ class _ChatState extends State<_Chat> { void openCameraAction(BuildContext context) async { if (kIsWeb) { - showToast(L10n.of(context).notSupportedInWeb); + BotToast.showText(text: L10n.of(context).notSupportedInWeb); return; } File file = await ImagePicker.pickImage( diff --git a/lib/views/chat_details.dart b/lib/views/chat_details.dart index 0c6f295..c43fddb 100644 --- a/lib/views/chat_details.dart +++ b/lib/views/chat_details.dart @@ -13,7 +13,7 @@ import 'package:fluffychat/views/invitation_selection.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:image_picker/image_picker.dart'; import 'package:link_text/link_text.dart'; import './settings_emotes.dart'; @@ -40,7 +40,7 @@ class _ChatDetailsState extends State { widget.room.setName(displayname), ); if (success != false) { - showToast(L10n.of(context).displaynameHasBeenChanged); + BotToast.showText(text: L10n.of(context).displaynameHasBeenChanged); } } @@ -101,7 +101,7 @@ class _ChatDetailsState extends State { widget.room.setDescription(displayname), ); if (success != false) { - showToast(L10n.of(context).groupDescriptionHasBeenChanged); + BotToast.showText(text: L10n.of(context).groupDescriptionHasBeenChanged); } } @@ -121,7 +121,7 @@ class _ChatDetailsState extends State { ), ); if (success != false) { - showToast(L10n.of(context).avatarHasBeenChanged); + BotToast.showText(text: L10n.of(context).avatarHasBeenChanged); } } @@ -172,7 +172,8 @@ class _ChatDetailsState extends State { Clipboard.setData( ClipboardData(text: widget.room.canonicalAlias), ); - showToast(L10n.of(context).copiedToClipboard); + BotToast.showText( + text: L10n.of(context).copiedToClipboard); }, ), ChatSettingsPopupMenu(widget.room, false) diff --git a/lib/views/invitation_selection.dart b/lib/views/invitation_selection.dart index 210a784..4e52924 100644 --- a/lib/views/invitation_selection.dart +++ b/lib/views/invitation_selection.dart @@ -7,7 +7,7 @@ import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/l10n/l10n.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'chat_list.dart'; @@ -58,7 +58,7 @@ class _InvitationSelectionState extends State { widget.room.invite(id), ); if (success != false) { - showToast(L10n.of(context).contactHasBeenInvitedToTheGroup); + BotToast.showText(text: L10n.of(context).contactHasBeenInvitedToTheGroup); } } diff --git a/lib/views/settings_emotes.dart b/lib/views/settings_emotes.dart index 101305f..6b28909 100644 --- a/lib/views/settings_emotes.dart +++ b/lib/views/settings_emotes.dart @@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter_advanced_networkimage/provider.dart'; import 'package:famedlysdk/famedlysdk.dart'; import 'package:image_picker/image_picker.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'chat_list.dart'; import '../components/adaptive_page_layout.dart'; @@ -371,7 +371,7 @@ class _EmoteImagePickerState extends State<_EmoteImagePicker> { ), onPressed: () async { if (kIsWeb) { - showToast(L10n.of(context).notSupportedInWeb); + BotToast.showText(text: L10n.of(context).notSupportedInWeb); return; } File file = await ImagePicker.pickImage( diff --git a/lib/views/sign_up_password.dart b/lib/views/sign_up_password.dart index 0b8d24c..1f16fbc 100644 --- a/lib/views/sign_up_password.dart +++ b/lib/views/sign_up_password.dart @@ -7,7 +7,7 @@ import 'package:fluffychat/l10n/l10n.dart'; import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/views/auth_web_view.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'chat_list.dart'; @@ -96,7 +96,7 @@ class _SignUpPasswordState extends State { try { await matrix.client.setDisplayname(widget.displayname); } catch (exception) { - showToast(L10n.of(context).couldNotSetDisplayname); + BotToast.showText(text: L10n.of(context).couldNotSetDisplayname); } if (widget.avatar != null) { try { @@ -107,7 +107,7 @@ class _SignUpPasswordState extends State { ), ); } catch (exception) { - showToast(L10n.of(context).couldNotSetAvatar); + BotToast.showText(text: L10n.of(context).couldNotSetAvatar); } } await Navigator.of(context).pushAndRemoveUntil( diff --git a/pubspec.lock b/pubspec.lock index 6910ab1..cd398f8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,6 +43,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + bot_toast: + dependency: "direct main" + description: + name: bot_toast + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" bubble: dependency: "direct main" description: @@ -216,13 +223,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.5" - flutter_styled_toast: - dependency: "direct main" - description: - name: flutter_styled_toast - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.1" flutter_svg: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d8e727d..4b492e4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -53,7 +53,7 @@ dependencies: flutter_sound: ^2.1.1 open_file: ^3.0.1 mime_type: ^0.3.0 - flutter_styled_toast: ^1.2.1 + bot_toast: ^3.0.0 flutter_matrix_html: ^0.0.5 intl: ^0.16.0