Skip to content

Commit

Permalink
dialog [nfc]: inline _materialDialogActionTest in _adaptiveAction
Browse files Browse the repository at this point in the history
  • Loading branch information
u7088495 committed Oct 25, 2024
1 parent 9d2c4df commit 9e6fc98
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions lib/widgets/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,20 @@ 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));
// 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.
return TextButton(onPressed: onPressed, child: Text(text, textAlign: TextAlign.end));
case TargetPlatform.iOS:
case TargetPlatform.macOS:
return CupertinoDialogAction(onPressed: onPressed, child: Text(text));
Expand Down

0 comments on commit 9e6fc98

Please sign in to comment.