Skip to content

Commit

Permalink
feat: Added neutral action to Smooth Alert dialog and updated app rev…
Browse files Browse the repository at this point in the history
…iew dialog in login page (#5086)

* Added neutral action and updated app review dialog

* Changed the button labels and removed the top button with two buttons below design

* Refactored the injecting small space logic to be correct

Co-authored-by: monsieurtanuki <[email protected]>

---------

Co-authored-by: monsieurtanuki <[email protected]>
  • Loading branch information
Smit56R and monsieurtanuki authored Feb 25, 2024
1 parent e3aea8c commit d704b58
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SmoothAlertDialog extends StatelessWidget {
required this.body,
this.positiveAction,
this.negativeAction,
this.neutralAction,
this.actionsAxis,
this.actionsOrder,
this.close = false,
Expand All @@ -44,6 +45,7 @@ class SmoothAlertDialog extends StatelessWidget {
final Widget body;
final SmoothActionButton? positiveAction;
final SmoothActionButton? negativeAction;
final SmoothActionButton? neutralAction;
final Axis? actionsAxis;
final SmoothButtonsBarOrder? actionsOrder;
final EdgeInsets? margin;
Expand Down Expand Up @@ -103,9 +105,15 @@ class SmoothAlertDialog extends StatelessWidget {
}

Padding _buildBottomBar(EdgeInsetsDirectional padding) {
final bool singleButton =
positiveAction != null && negativeAction == null ||
negativeAction != null && positiveAction == null;
final bool singleButton = (positiveAction != null &&
negativeAction == null &&
neutralAction == null) ||
(negativeAction != null &&
positiveAction == null &&
neutralAction == null) ||
(neutralAction != null &&
positiveAction == null &&
negativeAction == null);

return Padding(
padding: EdgeInsetsDirectional.only(
Expand All @@ -120,13 +128,15 @@ class SmoothAlertDialog extends StatelessWidget {
child: SmoothActionButtonsBar(
positiveAction: positiveAction,
negativeAction: negativeAction,
neutralAction: neutralAction,
axis: actionsAxis,
order: actionsOrder,
),
);
}

bool get hasActions => positiveAction != null || negativeAction != null;
bool get hasActions =>
positiveAction != null || negativeAction != null || neutralAction != null;

Widget _buildContent(final BuildContext context) => DefaultTextStyle.merge(
style: const TextStyle(height: 1.5),
Expand Down Expand Up @@ -245,11 +255,15 @@ class SmoothActionButtonsBar extends StatelessWidget {
const SmoothActionButtonsBar({
this.positiveAction,
this.negativeAction,
this.neutralAction,
this.axis,
this.order,
this.padding,
super.key,
}) : assert(positiveAction != null || negativeAction != null,
}) : assert(
positiveAction != null ||
negativeAction != null ||
neutralAction != null,
'At least one action must be passed!');

const SmoothActionButtonsBar.single({
Expand All @@ -262,6 +276,7 @@ class SmoothActionButtonsBar extends StatelessWidget {

final SmoothActionButton? positiveAction;
final SmoothActionButton? negativeAction;
final SmoothActionButton? neutralAction;
final Axis? axis;
final SmoothButtonsBarOrder? order;
final EdgeInsetsGeometry? padding;
Expand All @@ -275,11 +290,20 @@ class SmoothActionButtonsBar extends StatelessWidget {
order ?? SmoothButtonsBarOrder.auto,
positiveAction: positiveAction,
negativeAction: negativeAction,
neutralAction: neutralAction,
)!;

if (buttonsAxis == Axis.horizontal) {
// With two buttons, inject a small space between them
if (actions.length == 2) {
// With multiple buttons, inject a small space between them
if (actions.length > 1) {
if (actions.length > 2) {
// space injected before 3rd item
actions.insert(
2,
const SizedBox(width: VERY_SMALL_SPACE),
);
}
// space injected before 2nd item
actions.insert(
1,
const SizedBox(width: VERY_SMALL_SPACE),
Expand Down Expand Up @@ -324,8 +348,11 @@ List<Widget>? _buildActions(
SmoothButtonsBarOrder order, {
SmoothActionButton? positiveAction,
SmoothActionButton? negativeAction,
SmoothActionButton? neutralAction,
}) {
if (positiveAction == null && negativeAction == null) {
if (positiveAction == null &&
negativeAction == null &&
neutralAction == null) {
return null;
}

Expand All @@ -340,6 +367,12 @@ List<Widget>? _buildActions(
buttonData: negativeAction,
),
),
if (neutralAction != null)
Expanded(
child: _SmoothActionFlatButton(
buttonData: neutralAction,
),
),
if (positiveAction != null)
Expanded(
child: _SmoothActionElevatedButton(
Expand All @@ -357,6 +390,13 @@ List<Widget>? _buildActions(
buttonData: positiveAction,
),
),
if (neutralAction != null)
SizedBox(
width: double.infinity,
child: _SmoothActionFlatButton(
buttonData: neutralAction,
),
),
if (negativeAction != null)
SizedBox(
width: double.infinity,
Expand Down
9 changes: 6 additions & 3 deletions packages/smooth_app/lib/pages/user_management/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,17 @@ class _LoginPageState extends State<LoginPage> with TraceableClientMixin {
builder: (BuildContext context) => SmoothAlertDialog(
body: Text(appLocalizations.app_rating_dialog_title_enjoying_app),
positiveAction: SmoothActionButton(
text: appLocalizations
.app_rating_dialog_title_enjoying_positive_actions,
text: appLocalizations.tagline_app_review_button_positive,
onPressed: () => Navigator.of(context).pop(true),
),
negativeAction: SmoothActionButton(
text: appLocalizations.not_really,
text: appLocalizations.tagline_app_review_button_negative,
onPressed: () => Navigator.of(context).pop(false),
),
neutralAction: SmoothActionButton(
text: appLocalizations.tagline_app_review_button_later,
onPressed: () => Navigator.of(context).pop(null),
),
),
);
if (enjoyingApp == null) {
Expand Down

0 comments on commit d704b58

Please sign in to comment.