mirror of
				https://gitlab.com/famedly/fluffychat.git
				synced 2025-11-04 06:17:26 +01:00 
			
		
		
		
	refactor: Switch to TextButton
This commit is contained in:
		
							parent
							
								
									ac6fcd1594
								
							
						
					
					
						commit
						55803d1d3f
					
				@ -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,
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -74,7 +74,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
 | 
			
		||||
      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<BootstrapDialog> {
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
      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<BootstrapDialog> {
 | 
			
		||||
                );
 | 
			
		||||
          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<BootstrapDialog> {
 | 
			
		||||
            },
 | 
			
		||||
          ));
 | 
			
		||||
          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<BootstrapDialog> {
 | 
			
		||||
            },
 | 
			
		||||
          ));
 | 
			
		||||
          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<BootstrapDialog> {
 | 
			
		||||
            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<bool>(false),
 | 
			
		||||
          ));
 | 
			
		||||
@ -245,7 +245,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
 | 
			
		||||
            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<bool>(false),
 | 
			
		||||
          ));
 | 
			
		||||
 | 
			
		||||
@ -132,14 +132,14 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
 | 
			
		||||
          ),
 | 
			
		||||
        );
 | 
			
		||||
        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<KeyVerificationDialog> {
 | 
			
		||||
          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<KeyVerificationDialog> {
 | 
			
		||||
            .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<KeyVerificationDialog> {
 | 
			
		||||
        );
 | 
			
		||||
        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<KeyVerificationDialog> {
 | 
			
		||||
          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<KeyVerificationDialog> {
 | 
			
		||||
          ],
 | 
			
		||||
          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;
 | 
			
		||||
 | 
			
		||||
@ -71,12 +71,12 @@ class _PermissionSliderDialogState extends State<PermissionSliderDialog> {
 | 
			
		||||
    );
 | 
			
		||||
    final buttons = [
 | 
			
		||||
      AdaptiveFlatButton(
 | 
			
		||||
        child: Text(L10n.of(context).cancel),
 | 
			
		||||
       label: L10n.of(context).cancel,
 | 
			
		||||
        onPressed: () =>
 | 
			
		||||
            Navigator.of(context, rootNavigator: false).pop<int>(null),
 | 
			
		||||
      ),
 | 
			
		||||
      AdaptiveFlatButton(
 | 
			
		||||
        child: Text(L10n.of(context).confirm),
 | 
			
		||||
      label: L10n.of(context).confirm,
 | 
			
		||||
        onPressed: () =>
 | 
			
		||||
            Navigator.of(context, rootNavigator: false).pop<int>(_permission),
 | 
			
		||||
      ),
 | 
			
		||||
 | 
			
		||||
@ -107,7 +107,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
 | 
			
		||||
        ],
 | 
			
		||||
      ),
 | 
			
		||||
      actions: <Widget>[
 | 
			
		||||
        FlatButton(
 | 
			
		||||
        TextButton(
 | 
			
		||||
          child: Text(
 | 
			
		||||
            L10n.of(context).cancel.toUpperCase(),
 | 
			
		||||
            style: TextStyle(
 | 
			
		||||
@ -116,7 +116,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
 | 
			
		||||
          ),
 | 
			
		||||
          onPressed: () => Navigator.of(context, rootNavigator: false).pop(),
 | 
			
		||||
        ),
 | 
			
		||||
        FlatButton(
 | 
			
		||||
        TextButton(
 | 
			
		||||
          child: Row(
 | 
			
		||||
            children: <Widget>[
 | 
			
		||||
              Text(L10n.of(context).send.toUpperCase()),
 | 
			
		||||
 | 
			
		||||
@ -77,14 +77,14 @@ class _SendFileDialogState extends State<SendFileDialog> {
 | 
			
		||||
      title: Text(sendStr),
 | 
			
		||||
      content: contentWidget,
 | 
			
		||||
      actions: <Widget>[
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
@ -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<Matrix> 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);
 | 
			
		||||
 | 
			
		||||
@ -754,7 +754,7 @@ class _ChatState extends State<Chat> {
 | 
			
		||||
                                        child: CircularProgressIndicator(),
 | 
			
		||||
                                      )
 | 
			
		||||
                                    : _canLoadMore
 | 
			
		||||
                                        ? FlatButton(
 | 
			
		||||
                                        ? TextButton(
 | 
			
		||||
                                            child: Text(
 | 
			
		||||
                                              L10n.of(context).loadMore,
 | 
			
		||||
                                              style: TextStyle(
 | 
			
		||||
@ -1014,7 +1014,7 @@ class _ChatState extends State<Chat> {
 | 
			
		||||
                              ? <Widget>[
 | 
			
		||||
                                  Container(
 | 
			
		||||
                                    height: 56,
 | 
			
		||||
                                    child: FlatButton(
 | 
			
		||||
                                    child: TextButton(
 | 
			
		||||
                                      onPressed: () =>
 | 
			
		||||
                                          forwardEventsAction(context),
 | 
			
		||||
                                      child: Row(
 | 
			
		||||
@ -1033,7 +1033,7 @@ class _ChatState extends State<Chat> {
 | 
			
		||||
                                              0
 | 
			
		||||
                                          ? Container(
 | 
			
		||||
                                              height: 56,
 | 
			
		||||
                                              child: FlatButton(
 | 
			
		||||
                                              child: TextButton(
 | 
			
		||||
                                                onPressed: () => replyAction(),
 | 
			
		||||
                                                child: Row(
 | 
			
		||||
                                                  children: <Widget>[
 | 
			
		||||
@ -1047,7 +1047,7 @@ class _ChatState extends State<Chat> {
 | 
			
		||||
                                            )
 | 
			
		||||
                                          : Container(
 | 
			
		||||
                                              height: 56,
 | 
			
		||||
                                              child: FlatButton(
 | 
			
		||||
                                              child: TextButton(
 | 
			
		||||
                                                onPressed: () =>
 | 
			
		||||
                                                    sendAgainAction(timeline),
 | 
			
		||||
                                                child: Row(
 | 
			
		||||
 | 
			
		||||
@ -174,8 +174,12 @@ class _ChatListState extends State<ChatList> {
 | 
			
		||||
 | 
			
		||||
  final GlobalKey<DefaultAppBarSearchFieldState> _searchFieldKey = GlobalKey();
 | 
			
		||||
 | 
			
		||||
  Future<List<ThirdPartyIdentifier>> _thirdPartyIdentifierFuture;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    _thirdPartyIdentifierFuture ??=
 | 
			
		||||
        Matrix.of(context).client.requestThirdPartyIdentifiers();
 | 
			
		||||
    return StreamBuilder<Object>(
 | 
			
		||||
        stream: Matrix.of(context).onShareContentChanged.stream,
 | 
			
		||||
        builder: (_, __) {
 | 
			
		||||
 | 
			
		||||
@ -202,7 +202,7 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
 | 
			
		||||
            Wrap(
 | 
			
		||||
              alignment: WrapAlignment.center,
 | 
			
		||||
              children: [
 | 
			
		||||
                FlatButton(
 | 
			
		||||
                TextButton(
 | 
			
		||||
                  child: Text(
 | 
			
		||||
                    L10n.of(context).privacy,
 | 
			
		||||
                    style: TextStyle(
 | 
			
		||||
@ -212,7 +212,7 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
 | 
			
		||||
                  ),
 | 
			
		||||
                  onPressed: () => launch(AppConfig.privacyUrl),
 | 
			
		||||
                ),
 | 
			
		||||
                FlatButton(
 | 
			
		||||
                TextButton(
 | 
			
		||||
                  child: Text(
 | 
			
		||||
                    L10n.of(context).about,
 | 
			
		||||
                    style: TextStyle(
 | 
			
		||||
 | 
			
		||||
@ -246,7 +246,7 @@ class _LoginState extends State<Login> {
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
            Center(
 | 
			
		||||
              child: FlatButton(
 | 
			
		||||
              child: TextButton(
 | 
			
		||||
                child: Text(
 | 
			
		||||
                  L10n.of(context).passwordForgotten,
 | 
			
		||||
                  style: TextStyle(
 | 
			
		||||
 | 
			
		||||
@ -90,7 +90,7 @@ class _NewPrivateChatState extends State<NewPrivateChat> {
 | 
			
		||||
        title: Text(L10n.of(context).newChat),
 | 
			
		||||
        elevation: 0,
 | 
			
		||||
        actions: [
 | 
			
		||||
          FlatButton(
 | 
			
		||||
          TextButton(
 | 
			
		||||
            child: Text(
 | 
			
		||||
              L10n.of(context).createNewGroup,
 | 
			
		||||
              style: TextStyle(color: Theme.of(context).accentColor),
 | 
			
		||||
 | 
			
		||||
@ -158,7 +158,7 @@ class _SignUpState extends State<SignUp> {
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
            Center(
 | 
			
		||||
              child: FlatButton(
 | 
			
		||||
              child: TextButton(
 | 
			
		||||
                child: Text(
 | 
			
		||||
                  L10n.of(context).alreadyHaveAnAccount,
 | 
			
		||||
                  style: TextStyle(
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user