Skip to content

Commit

Permalink
dialog [nfc]: Inline _materialDialogActionTest in _adaptiveAction
Browse files Browse the repository at this point in the history
As suggested at:
  zulip#1017 (comment)
  • Loading branch information
u7088495 committed Oct 26, 2024
1 parent f365734 commit 6166a0a
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions lib/widgets/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
import 'package:flutter/foundation.dart';

Widget _materialDialogActionText(String text) {
return Text(
text,

// As suggested by
// https://api.flutter.dev/flutter/material/AlertDialog/actions.html :
// > It is recommended to set the Text.textAlign to TextAlign.end
// > for the Text within the TextButton, so that buttons whose
// > labels wrap to an extra line align with the overall
// > OverflowBar's alignment within the dialog.
textAlign: TextAlign.end,
);
}

/// A platform-appropriate action for [AlertDialog.adaptive]'s [actions] param.
Widget _adaptiveAction({required VoidCallback onPressed, required String text}) {
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
return TextButton(onPressed: onPressed, child: _materialDialogActionText(text));
return TextButton(
onPressed: onPressed,
child: Text(
text,
// As suggested by
// https://api.flutter.dev/flutter/material/AlertDialog/actions.html :
// > It is recommended to set the Text.textAlign to TextAlign.end
// > for the Text within the TextButton, so that buttons whose
// > labels wrap to an extra line align with the overall
// > OverflowBar's alignment within the dialog.
textAlign: TextAlign.end));
case TargetPlatform.iOS:
case TargetPlatform.macOS:
return CupertinoDialogAction(onPressed: onPressed, child: Text(text));
return CupertinoDialogAction(
onPressed: onPressed,
child: Text(text));
}
}

Expand Down Expand Up @@ -90,4 +88,4 @@ void showSuggestedActionDialog({
onPressed: onActionButtonPress,
text: actionButtonText ?? zulipLocalizations.dialogContinue),
]));
}
}

0 comments on commit 6166a0a

Please sign in to comment.