refactor: Switch to TextButton

This commit is contained in:
Christian Pauly 2021-02-27 07:53:34 +01:00
parent ac6fcd1594
commit 55803d1d3f
13 changed files with 45 additions and 67 deletions

View File

@ -3,13 +3,13 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AdaptiveFlatButton extends StatelessWidget { class AdaptiveFlatButton extends StatelessWidget {
final Widget child; final String label;
final Color textColor; final Color textColor;
final Function onPressed; final Function onPressed;
const AdaptiveFlatButton({ const AdaptiveFlatButton({
Key key, Key key,
this.child, @required this.label,
this.textColor, this.textColor,
this.onPressed, this.onPressed,
}) : super(key: key); }) : super(key: key);
@ -18,14 +18,16 @@ class AdaptiveFlatButton extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (PlatformInfos.isCupertinoStyle) { if (PlatformInfos.isCupertinoStyle) {
return CupertinoDialogAction( return CupertinoDialogAction(
child: child, child: Text(label),
onPressed: onPressed, onPressed: onPressed,
textStyle: textColor != null ? TextStyle(color: textColor) : null, textStyle: textColor != null ? TextStyle(color: textColor) : null,
); );
} }
return FlatButton( return TextButton(
child: child, child: Text(
textColor: textColor, label,
style: TextStyle(color: textColor),
),
onPressed: onPressed, onPressed: onPressed,
); );
} }

View File

@ -74,7 +74,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
titleText = L10n.of(context).chatBackup; titleText = L10n.of(context).chatBackup;
body = Text(L10n.of(context).chatBackupDescription); body = Text(L10n.of(context).chatBackupDescription);
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).next), label: L10n.of(context).next,
onPressed: () => _createBootstrap(false), onPressed: () => _createBootstrap(false),
)); ));
} else if (bootstrap.newSsssKey?.recoveryKey != null && } else if (bootstrap.newSsssKey?.recoveryKey != null &&
@ -95,11 +95,11 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
), ),
); );
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).copyToClipboard), label: L10n.of(context).copyToClipboard,
onPressed: () => Clipboard.setData(ClipboardData(text: key)), onPressed: () => Clipboard.setData(ClipboardData(text: key)),
)); ));
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).next), label: L10n.of(context).next,
onPressed: () => setState(() => _recoveryKeyStored = true), onPressed: () => setState(() => _recoveryKeyStored = true),
)); ));
} else { } else {
@ -150,7 +150,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
); );
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
textColor: Colors.red, textColor: Colors.red,
child: Text('Lost security key'), label: 'Lost security key',
onPressed: () async { onPressed: () async {
if (OkCancelResult.ok == if (OkCancelResult.ok ==
await showOkCancelAlertDialog( await showOkCancelAlertDialog(
@ -167,7 +167,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
}, },
)); ));
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).transferFromAnotherDevice), label: L10n.of(context).transferFromAnotherDevice,
onPressed: () async { onPressed: () async {
final req = await Matrix.of(context) final req = await Matrix.of(context)
.client .client
@ -178,7 +178,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
}, },
)); ));
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).next), label: L10n.of(context).next,
onPressed: () async { onPressed: () async {
setState(() { setState(() {
_recoveryKeyInputError = null; _recoveryKeyInputError = null;
@ -232,7 +232,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
title: Text(L10n.of(context).oopsSomethingWentWrong), title: Text(L10n.of(context).oopsSomethingWentWrong),
); );
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).close), label: L10n.of(context).close,
onPressed: () => onPressed: () =>
Navigator.of(context, rootNavigator: false).pop<bool>(false), Navigator.of(context, rootNavigator: false).pop<bool>(false),
)); ));
@ -245,7 +245,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
title: Text(L10n.of(context).keysCached), title: Text(L10n.of(context).keysCached),
); );
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).close), label: L10n.of(context).close,
onPressed: () => onPressed: () =>
Navigator.of(context, rootNavigator: false).pop<bool>(false), Navigator.of(context, rootNavigator: false).pop<bool>(false),
)); ));

View File

@ -132,14 +132,14 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
), ),
); );
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).submit), label: L10n.of(context).submit,
onPressed: () { onPressed: () {
input = textEditingController.text; input = textEditingController.text;
checkInput(); checkInput();
}, },
)); ));
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).skip), label: L10n.of(context).skip,
onPressed: () => widget.request.openSSSS(skip: true), onPressed: () => widget.request.openSSSS(skip: true),
)); ));
break; break;
@ -151,11 +151,11 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
margin: EdgeInsets.only(left: 8.0, right: 8.0), margin: EdgeInsets.only(left: 8.0, right: 8.0),
); );
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).accept), label: L10n.of(context).accept,
onPressed: () => widget.request.acceptVerification(), onPressed: () => widget.request.acceptVerification(),
)); ));
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).reject), label: L10n.of(context).reject,
onPressed: () { onPressed: () {
widget.request.rejectVerification().then((_) { widget.request.rejectVerification().then((_) {
Navigator.of(context, rootNavigator: false).pop(); Navigator.of(context, rootNavigator: false).pop();
@ -181,7 +181,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
.deviceKeys[widget.request.deviceId]; .deviceKeys[widget.request.deviceId];
if (key != null) { if (key != null) {
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).verifyManual), label: L10n.of(context).verifyManual,
onPressed: () async { onPressed: () async {
final result = await showOkCancelAlertDialog( final result = await showOkCancelAlertDialog(
context: context, context: context,
@ -237,11 +237,11 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
); );
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
textColor: Colors.red, textColor: Colors.red,
child: Text(L10n.of(context).theyDontMatch), label: L10n.of(context).theyDontMatch,
onPressed: () => widget.request.rejectSas(), onPressed: () => widget.request.rejectSas(),
)); ));
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).theyMatch), label: L10n.of(context).theyMatch,
onPressed: () => widget.request.acceptSas(), onPressed: () => widget.request.acceptSas(),
)); ));
break; break;
@ -276,7 +276,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
); );
buttons.add(AdaptiveFlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).close), label: L10n.of(context).close,
onPressed: () => Navigator.of(context, rootNavigator: false).pop(), onPressed: () => Navigator.of(context, rootNavigator: false).pop(),
)); ));
break; break;
@ -292,8 +292,8 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
], ],
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
); );
buttons.add(FlatButton( buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).close), label: L10n.of(context).close,
onPressed: () => Navigator.of(context, rootNavigator: false).pop(), onPressed: () => Navigator.of(context, rootNavigator: false).pop(),
)); ));
break; break;

View File

@ -71,12 +71,12 @@ class _PermissionSliderDialogState extends State<PermissionSliderDialog> {
); );
final buttons = [ final buttons = [
AdaptiveFlatButton( AdaptiveFlatButton(
child: Text(L10n.of(context).cancel), label: L10n.of(context).cancel,
onPressed: () => onPressed: () =>
Navigator.of(context, rootNavigator: false).pop<int>(null), Navigator.of(context, rootNavigator: false).pop<int>(null),
), ),
AdaptiveFlatButton( AdaptiveFlatButton(
child: Text(L10n.of(context).confirm), label: L10n.of(context).confirm,
onPressed: () => onPressed: () =>
Navigator.of(context, rootNavigator: false).pop<int>(_permission), Navigator.of(context, rootNavigator: false).pop<int>(_permission),
), ),

View File

@ -107,7 +107,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
], ],
), ),
actions: <Widget>[ actions: <Widget>[
FlatButton( TextButton(
child: Text( child: Text(
L10n.of(context).cancel.toUpperCase(), L10n.of(context).cancel.toUpperCase(),
style: TextStyle( style: TextStyle(
@ -116,7 +116,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
), ),
onPressed: () => Navigator.of(context, rootNavigator: false).pop(), onPressed: () => Navigator.of(context, rootNavigator: false).pop(),
), ),
FlatButton( TextButton(
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Text(L10n.of(context).send.toUpperCase()), Text(L10n.of(context).send.toUpperCase()),

View File

@ -77,14 +77,14 @@ class _SendFileDialogState extends State<SendFileDialog> {
title: Text(sendStr), title: Text(sendStr),
content: contentWidget, content: contentWidget,
actions: <Widget>[ actions: <Widget>[
FlatButton( TextButton(
child: Text(L10n.of(context).cancel), child: Text(L10n.of(context).cancel),
onPressed: () { onPressed: () {
// just close the dialog // just close the dialog
Navigator.of(context, rootNavigator: false).pop(); Navigator.of(context, rootNavigator: false).pop();
}, },
), ),
FlatButton( TextButton(
child: Text(L10n.of(context).send), child: Text(L10n.of(context).send),
onPressed: _isSending onPressed: _isSending
? null ? null

View File

@ -9,7 +9,6 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/matrix_locals.dart'; import 'package:fluffychat/utils/matrix_locals.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/sentry_controller.dart'; import 'package:fluffychat/utils/sentry_controller.dart';
import 'package:flushbar/flushbar.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_app_lock/flutter_app_lock.dart'; import 'package:flutter_app_lock/flutter_app_lock.dart';
@ -83,33 +82,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
void _initWithStore() async { void _initWithStore() async {
try { try {
client.init(); 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) { } catch (e, s) {
client.onLoginStateChanged.sink.addError(e, s); client.onLoginStateChanged.sink.addError(e, s);
SentryController.captureException(e, s); SentryController.captureException(e, s);

View File

@ -754,7 +754,7 @@ class _ChatState extends State<Chat> {
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
) )
: _canLoadMore : _canLoadMore
? FlatButton( ? TextButton(
child: Text( child: Text(
L10n.of(context).loadMore, L10n.of(context).loadMore,
style: TextStyle( style: TextStyle(
@ -1014,7 +1014,7 @@ class _ChatState extends State<Chat> {
? <Widget>[ ? <Widget>[
Container( Container(
height: 56, height: 56,
child: FlatButton( child: TextButton(
onPressed: () => onPressed: () =>
forwardEventsAction(context), forwardEventsAction(context),
child: Row( child: Row(
@ -1033,7 +1033,7 @@ class _ChatState extends State<Chat> {
0 0
? Container( ? Container(
height: 56, height: 56,
child: FlatButton( child: TextButton(
onPressed: () => replyAction(), onPressed: () => replyAction(),
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
@ -1047,7 +1047,7 @@ class _ChatState extends State<Chat> {
) )
: Container( : Container(
height: 56, height: 56,
child: FlatButton( child: TextButton(
onPressed: () => onPressed: () =>
sendAgainAction(timeline), sendAgainAction(timeline),
child: Row( child: Row(

View File

@ -174,8 +174,12 @@ class _ChatListState extends State<ChatList> {
final GlobalKey<DefaultAppBarSearchFieldState> _searchFieldKey = GlobalKey(); final GlobalKey<DefaultAppBarSearchFieldState> _searchFieldKey = GlobalKey();
Future<List<ThirdPartyIdentifier>> _thirdPartyIdentifierFuture;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
_thirdPartyIdentifierFuture ??=
Matrix.of(context).client.requestThirdPartyIdentifiers();
return StreamBuilder<Object>( return StreamBuilder<Object>(
stream: Matrix.of(context).onShareContentChanged.stream, stream: Matrix.of(context).onShareContentChanged.stream,
builder: (_, __) { builder: (_, __) {

View File

@ -202,7 +202,7 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
Wrap( Wrap(
alignment: WrapAlignment.center, alignment: WrapAlignment.center,
children: [ children: [
FlatButton( TextButton(
child: Text( child: Text(
L10n.of(context).privacy, L10n.of(context).privacy,
style: TextStyle( style: TextStyle(
@ -212,7 +212,7 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
), ),
onPressed: () => launch(AppConfig.privacyUrl), onPressed: () => launch(AppConfig.privacyUrl),
), ),
FlatButton( TextButton(
child: Text( child: Text(
L10n.of(context).about, L10n.of(context).about,
style: TextStyle( style: TextStyle(

View File

@ -246,7 +246,7 @@ class _LoginState extends State<Login> {
), ),
), ),
Center( Center(
child: FlatButton( child: TextButton(
child: Text( child: Text(
L10n.of(context).passwordForgotten, L10n.of(context).passwordForgotten,
style: TextStyle( style: TextStyle(

View File

@ -90,7 +90,7 @@ class _NewPrivateChatState extends State<NewPrivateChat> {
title: Text(L10n.of(context).newChat), title: Text(L10n.of(context).newChat),
elevation: 0, elevation: 0,
actions: [ actions: [
FlatButton( TextButton(
child: Text( child: Text(
L10n.of(context).createNewGroup, L10n.of(context).createNewGroup,
style: TextStyle(color: Theme.of(context).accentColor), style: TextStyle(color: Theme.of(context).accentColor),

View File

@ -158,7 +158,7 @@ class _SignUpState extends State<SignUp> {
), ),
), ),
Center( Center(
child: FlatButton( child: TextButton(
child: Text( child: Text(
L10n.of(context).alreadyHaveAnAccount, L10n.of(context).alreadyHaveAnAccount,
style: TextStyle( style: TextStyle(