From 55803d1d3f7bc4edc5447d7ee8cfd6fced0d119f Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sat, 27 Feb 2021 07:53:34 +0100 Subject: [PATCH] refactor: Switch to TextButton --- .../dialogs/adaptive_flat_button.dart | 14 ++++++---- lib/components/dialogs/bootstrap_dialog.dart | 16 +++++------ .../dialogs/key_verification_dialog.dart | 20 ++++++------- .../dialogs/permission_slider_dialog.dart | 4 +-- lib/components/dialogs/recording_dialog.dart | 4 +-- lib/components/dialogs/send_file_dialog.dart | 4 +-- lib/components/matrix.dart | 28 ------------------- lib/views/chat.dart | 8 +++--- lib/views/chat_list.dart | 4 +++ lib/views/homeserver_picker.dart | 4 +-- lib/views/login.dart | 2 +- lib/views/new_private_chat.dart | 2 +- lib/views/sign_up.dart | 2 +- 13 files changed, 45 insertions(+), 67 deletions(-) diff --git a/lib/components/dialogs/adaptive_flat_button.dart b/lib/components/dialogs/adaptive_flat_button.dart index 50f0f767..afa5d42a 100644 --- a/lib/components/dialogs/adaptive_flat_button.dart +++ b/lib/components/dialogs/adaptive_flat_button.dart @@ -3,13 +3,13 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class AdaptiveFlatButton extends StatelessWidget { - final Widget child; + final String label; final Color textColor; final Function onPressed; const AdaptiveFlatButton({ Key key, - this.child, + @required this.label, this.textColor, this.onPressed, }) : super(key: key); @@ -18,14 +18,16 @@ class AdaptiveFlatButton extends StatelessWidget { Widget build(BuildContext context) { if (PlatformInfos.isCupertinoStyle) { return CupertinoDialogAction( - child: child, + child: Text(label), onPressed: onPressed, textStyle: textColor != null ? TextStyle(color: textColor) : null, ); } - return FlatButton( - child: child, - textColor: textColor, + return TextButton( + child: Text( + label, + style: TextStyle(color: textColor), + ), onPressed: onPressed, ); } diff --git a/lib/components/dialogs/bootstrap_dialog.dart b/lib/components/dialogs/bootstrap_dialog.dart index 24133a5a..19af1312 100644 --- a/lib/components/dialogs/bootstrap_dialog.dart +++ b/lib/components/dialogs/bootstrap_dialog.dart @@ -74,7 +74,7 @@ class _BootstrapDialogState extends State { titleText = L10n.of(context).chatBackup; body = Text(L10n.of(context).chatBackupDescription); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).next), + label: L10n.of(context).next, onPressed: () => _createBootstrap(false), )); } else if (bootstrap.newSsssKey?.recoveryKey != null && @@ -95,11 +95,11 @@ class _BootstrapDialogState extends State { ), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).copyToClipboard), + label: L10n.of(context).copyToClipboard, onPressed: () => Clipboard.setData(ClipboardData(text: key)), )); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).next), + label: L10n.of(context).next, onPressed: () => setState(() => _recoveryKeyStored = true), )); } else { @@ -150,7 +150,7 @@ class _BootstrapDialogState extends State { ); buttons.add(AdaptiveFlatButton( textColor: Colors.red, - child: Text('Lost security key'), + label: 'Lost security key', onPressed: () async { if (OkCancelResult.ok == await showOkCancelAlertDialog( @@ -167,7 +167,7 @@ class _BootstrapDialogState extends State { }, )); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).transferFromAnotherDevice), + label: L10n.of(context).transferFromAnotherDevice, onPressed: () async { final req = await Matrix.of(context) .client @@ -178,7 +178,7 @@ class _BootstrapDialogState extends State { }, )); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).next), + label: L10n.of(context).next, onPressed: () async { setState(() { _recoveryKeyInputError = null; @@ -232,7 +232,7 @@ class _BootstrapDialogState extends State { title: Text(L10n.of(context).oopsSomethingWentWrong), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).close), + label: L10n.of(context).close, onPressed: () => Navigator.of(context, rootNavigator: false).pop(false), )); @@ -245,7 +245,7 @@ class _BootstrapDialogState extends State { title: Text(L10n.of(context).keysCached), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).close), + label: L10n.of(context).close, onPressed: () => Navigator.of(context, rootNavigator: false).pop(false), )); diff --git a/lib/components/dialogs/key_verification_dialog.dart b/lib/components/dialogs/key_verification_dialog.dart index 37236a34..c65294e0 100644 --- a/lib/components/dialogs/key_verification_dialog.dart +++ b/lib/components/dialogs/key_verification_dialog.dart @@ -132,14 +132,14 @@ class _KeyVerificationPageState extends State { ), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).submit), + label: L10n.of(context).submit, onPressed: () { input = textEditingController.text; checkInput(); }, )); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).skip), + label: L10n.of(context).skip, onPressed: () => widget.request.openSSSS(skip: true), )); break; @@ -151,11 +151,11 @@ class _KeyVerificationPageState extends State { margin: EdgeInsets.only(left: 8.0, right: 8.0), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).accept), + label: L10n.of(context).accept, onPressed: () => widget.request.acceptVerification(), )); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).reject), + label: L10n.of(context).reject, onPressed: () { widget.request.rejectVerification().then((_) { Navigator.of(context, rootNavigator: false).pop(); @@ -181,7 +181,7 @@ class _KeyVerificationPageState extends State { .deviceKeys[widget.request.deviceId]; if (key != null) { buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).verifyManual), + label: L10n.of(context).verifyManual, onPressed: () async { final result = await showOkCancelAlertDialog( context: context, @@ -237,11 +237,11 @@ class _KeyVerificationPageState extends State { ); buttons.add(AdaptiveFlatButton( textColor: Colors.red, - child: Text(L10n.of(context).theyDontMatch), + label: L10n.of(context).theyDontMatch, onPressed: () => widget.request.rejectSas(), )); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).theyMatch), + label: L10n.of(context).theyMatch, onPressed: () => widget.request.acceptSas(), )); break; @@ -276,7 +276,7 @@ class _KeyVerificationPageState extends State { mainAxisSize: MainAxisSize.min, ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).close), + label: L10n.of(context).close, onPressed: () => Navigator.of(context, rootNavigator: false).pop(), )); break; @@ -292,8 +292,8 @@ class _KeyVerificationPageState extends State { ], mainAxisSize: MainAxisSize.min, ); - buttons.add(FlatButton( - child: Text(L10n.of(context).close), + buttons.add(AdaptiveFlatButton( + label: L10n.of(context).close, onPressed: () => Navigator.of(context, rootNavigator: false).pop(), )); break; diff --git a/lib/components/dialogs/permission_slider_dialog.dart b/lib/components/dialogs/permission_slider_dialog.dart index b080428a..5ef2ceab 100644 --- a/lib/components/dialogs/permission_slider_dialog.dart +++ b/lib/components/dialogs/permission_slider_dialog.dart @@ -71,12 +71,12 @@ class _PermissionSliderDialogState extends State { ); final buttons = [ AdaptiveFlatButton( - child: Text(L10n.of(context).cancel), + label: L10n.of(context).cancel, onPressed: () => Navigator.of(context, rootNavigator: false).pop(null), ), AdaptiveFlatButton( - child: Text(L10n.of(context).confirm), + label: L10n.of(context).confirm, onPressed: () => Navigator.of(context, rootNavigator: false).pop(_permission), ), diff --git a/lib/components/dialogs/recording_dialog.dart b/lib/components/dialogs/recording_dialog.dart index 09b68493..995bbde8 100644 --- a/lib/components/dialogs/recording_dialog.dart +++ b/lib/components/dialogs/recording_dialog.dart @@ -107,7 +107,7 @@ class _RecordingDialogState extends State { ], ), actions: [ - FlatButton( + TextButton( child: Text( L10n.of(context).cancel.toUpperCase(), style: TextStyle( @@ -116,7 +116,7 @@ class _RecordingDialogState extends State { ), onPressed: () => Navigator.of(context, rootNavigator: false).pop(), ), - FlatButton( + TextButton( child: Row( children: [ Text(L10n.of(context).send.toUpperCase()), diff --git a/lib/components/dialogs/send_file_dialog.dart b/lib/components/dialogs/send_file_dialog.dart index 080c59d8..2d002739 100644 --- a/lib/components/dialogs/send_file_dialog.dart +++ b/lib/components/dialogs/send_file_dialog.dart @@ -77,14 +77,14 @@ class _SendFileDialogState extends State { title: Text(sendStr), content: contentWidget, actions: [ - FlatButton( + TextButton( child: Text(L10n.of(context).cancel), onPressed: () { // just close the dialog Navigator.of(context, rootNavigator: false).pop(); }, ), - FlatButton( + TextButton( child: Text(L10n.of(context).send), onPressed: _isSending ? null diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index f16c1354..71e999ad 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -9,7 +9,6 @@ import 'package:famedlysdk/famedlysdk.dart'; import 'package:fluffychat/utils/matrix_locals.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/sentry_controller.dart'; -import 'package:flushbar/flushbar.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_app_lock/flutter_app_lock.dart'; @@ -83,33 +82,6 @@ class MatrixState extends State with WidgetsBindingObserver { void _initWithStore() async { try { client.init(); - - final storeItem = await store.getItem(SettingKeys.showNoPid); - final configOptionMissing = storeItem == null || storeItem.isEmpty; - if (configOptionMissing || (!configOptionMissing && storeItem == '1')) { - if (configOptionMissing) { - await store.setItem(SettingKeys.showNoPid, '0'); - } - await client.requestThirdPartyIdentifiers().then((l) { - if (l.isEmpty) { - Flushbar( - title: L10n.of(context).warning, - message: L10n.of(context).noPasswordRecoveryDescription, - mainButton: RaisedButton( - elevation: 7, - color: Theme.of(context).scaffoldBackgroundColor, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(6), - ), - child: Text(L10n.of(context).edit), - onPressed: () => - AdaptivePageLayout.of(context).pushNamed('/settings/3pid'), - ), - flushbarStyle: FlushbarStyle.FLOATING, - ).show(context); - } - }).catchError((_) => null); - } } catch (e, s) { client.onLoginStateChanged.sink.addError(e, s); SentryController.captureException(e, s); diff --git a/lib/views/chat.dart b/lib/views/chat.dart index 292e542e..45cd35de 100644 --- a/lib/views/chat.dart +++ b/lib/views/chat.dart @@ -754,7 +754,7 @@ class _ChatState extends State { child: CircularProgressIndicator(), ) : _canLoadMore - ? FlatButton( + ? TextButton( child: Text( L10n.of(context).loadMore, style: TextStyle( @@ -1014,7 +1014,7 @@ class _ChatState extends State { ? [ Container( height: 56, - child: FlatButton( + child: TextButton( onPressed: () => forwardEventsAction(context), child: Row( @@ -1033,7 +1033,7 @@ class _ChatState extends State { 0 ? Container( height: 56, - child: FlatButton( + child: TextButton( onPressed: () => replyAction(), child: Row( children: [ @@ -1047,7 +1047,7 @@ class _ChatState extends State { ) : Container( height: 56, - child: FlatButton( + child: TextButton( onPressed: () => sendAgainAction(timeline), child: Row( diff --git a/lib/views/chat_list.dart b/lib/views/chat_list.dart index 29b7aec4..89306a20 100644 --- a/lib/views/chat_list.dart +++ b/lib/views/chat_list.dart @@ -174,8 +174,12 @@ class _ChatListState extends State { final GlobalKey _searchFieldKey = GlobalKey(); + Future> _thirdPartyIdentifierFuture; + @override Widget build(BuildContext context) { + _thirdPartyIdentifierFuture ??= + Matrix.of(context).client.requestThirdPartyIdentifiers(); return StreamBuilder( stream: Matrix.of(context).onShareContentChanged.stream, builder: (_, __) { diff --git a/lib/views/homeserver_picker.dart b/lib/views/homeserver_picker.dart index f962d91e..b2f19938 100644 --- a/lib/views/homeserver_picker.dart +++ b/lib/views/homeserver_picker.dart @@ -202,7 +202,7 @@ class _HomeserverPickerState extends State { Wrap( alignment: WrapAlignment.center, children: [ - FlatButton( + TextButton( child: Text( L10n.of(context).privacy, style: TextStyle( @@ -212,7 +212,7 @@ class _HomeserverPickerState extends State { ), onPressed: () => launch(AppConfig.privacyUrl), ), - FlatButton( + TextButton( child: Text( L10n.of(context).about, style: TextStyle( diff --git a/lib/views/login.dart b/lib/views/login.dart index 307f97a0..c9e1b173 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -246,7 +246,7 @@ class _LoginState extends State { ), ), Center( - child: FlatButton( + child: TextButton( child: Text( L10n.of(context).passwordForgotten, style: TextStyle( diff --git a/lib/views/new_private_chat.dart b/lib/views/new_private_chat.dart index 78f57ebe..ecb0fb10 100644 --- a/lib/views/new_private_chat.dart +++ b/lib/views/new_private_chat.dart @@ -90,7 +90,7 @@ class _NewPrivateChatState extends State { title: Text(L10n.of(context).newChat), elevation: 0, actions: [ - FlatButton( + TextButton( child: Text( L10n.of(context).createNewGroup, style: TextStyle(color: Theme.of(context).accentColor), diff --git a/lib/views/sign_up.dart b/lib/views/sign_up.dart index 6ab6e73c..cbb2e1fa 100644 --- a/lib/views/sign_up.dart +++ b/lib/views/sign_up.dart @@ -158,7 +158,7 @@ class _SignUpState extends State { ), ), Center( - child: FlatButton( + child: TextButton( child: Text( L10n.of(context).alreadyHaveAnAccount, style: TextStyle(