Skip to content

Commit

Permalink
Revert "feat: Smooth Dialog with an axis for buttons (openfoodfacts#2587
Browse files Browse the repository at this point in the history
)" (openfoodfacts#2608)

This reverts commit 4255a5f.
  • Loading branch information
g123k authored Jul 15, 2022
1 parent 6c22a17 commit 6b52473
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class SmoothAlertDialog extends StatelessWidget {
required this.body,
this.positiveAction,
this.negativeAction,
this.actionsAxis,
this.close = false,
});

Expand All @@ -30,7 +29,6 @@ class SmoothAlertDialog extends StatelessWidget {
final Widget body;
final SmoothActionButton? positiveAction;
final SmoothActionButton? negativeAction;
final Axis? actionsAxis;

static const EdgeInsets _contentPadding = EdgeInsets.only(
left: 24.0,
Expand Down Expand Up @@ -68,7 +66,6 @@ class SmoothAlertDialog extends StatelessWidget {
child: SmoothActionButtonsBar(
positiveAction: positiveAction,
negativeAction: negativeAction,
axis: actionsAxis,
),
);
}
Expand Down Expand Up @@ -126,15 +123,10 @@ class SmoothAlertDialog extends StatelessWidget {
}
}

/// Will display one or two buttons.
/// If the [axis] is [Axis.horizontal], the positive button will be on the end
/// If the [axis] is [Axis.vertical], the positive button will be on the start
/// Note: This Widget supports both RTL and LTR languages.
class SmoothActionButtonsBar extends StatelessWidget {
const SmoothActionButtonsBar({
this.positiveAction,
this.negativeAction,
this.axis,
super.key,
}) : assert(positiveAction != null || negativeAction != null,
'At least one action must be passed!');
Expand All @@ -149,84 +141,46 @@ class SmoothActionButtonsBar extends StatelessWidget {

final SmoothActionButton? positiveAction;
final SmoothActionButton? negativeAction;
final Axis? axis;

@override
Widget build(BuildContext context) {
final Axis buttonsAxis = axis ?? Axis.horizontal;
final List<Widget> actions = _buildActions(
context,
buttonsAxis,
positiveAction: positiveAction,
negativeAction: negativeAction,
)!;

if (axis == Axis.horizontal) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: actions,
);
} else {
return IntrinsicWidth(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: actions,
),
);
}
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: _buildActions(
context,
positiveAction: positiveAction,
negativeAction: negativeAction,
)!,
);
}
}

/// Generates Actions buttons with:
/// In LTR mode: Negative - Positive
/// In RTL mode: Positive - Negative
List<Widget>? _buildActions(
BuildContext context,
Axis axis, {
BuildContext context, {
SmoothActionButton? positiveAction,
SmoothActionButton? negativeAction,
}) {
if (positiveAction == null && negativeAction == null) {
return null;
}

List<Widget> actions;

if (axis == Axis.horizontal) {
// Negative action first
actions = <Widget>[
if (negativeAction != null)
Expanded(
child: _SmoothActionFlatButton(
buttonData: negativeAction,
),
),
if (positiveAction != null)
Expanded(
child: _SmoothActionElevatedButton(
buttonData: positiveAction,
),
),
];
} else {
// Positive first
actions = <Widget>[
if (positiveAction != null)
SizedBox(
width: double.infinity,
child: _SmoothActionElevatedButton(
buttonData: positiveAction,
),
final List<Widget> actions = <Widget>[
if (negativeAction != null)
Expanded(
child: _SmoothActionFlatButton(
buttonData: negativeAction,
),
if (negativeAction != null)
SizedBox(
width: double.infinity,
child: _SmoothActionFlatButton(
buttonData: negativeAction,
),
),
if (positiveAction != null)
Expanded(
child: _SmoothActionElevatedButton(
buttonData: positiveAction,
),
];
}
),
];

if (Directionality.of(context) == TextDirection.rtl) {
return actions.reversed.toList(growable: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ProductRefresher {
context: context,
builder: (BuildContext context) => SmoothAlertDialog(
body: Text(appLocalizations.sign_in_mandatory),
actionsAxis: Axis.vertical,
positiveAction: SmoothActionButton(
text: appLocalizations.sign_in,
onPressed: () async {
Expand Down

0 comments on commit 6b52473

Please sign in to comment.