Skip to content

Commit

Permalink
Use Navigator.of(context) inside showAlertDialog so MaterialApp.route…
Browse files Browse the repository at this point in the history
…r is not needed in tests

# Conflicts:
#	ecommerce_app/lib/src/common_widgets/alert_dialogs.dart
  • Loading branch information
bizz84 committed Dec 20, 2023
1 parent 6378b70 commit 820bba9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions ecommerce_app/lib/src/common_widgets/alert_dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:ecommerce_app/src/localization/string_hardcoded.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

/// Generic function to show a platform-aware Material or Cupertino dialog
Future<bool?> showAlertDialog({
Expand All @@ -28,22 +27,22 @@ Future<bool?> showAlertDialog({
if (cancelActionText != null)
TextButton(
child: Text(cancelActionText),
onPressed: () => context.pop(false),
onPressed: () => Navigator.of(context).pop(false),
),
TextButton(
child: Text(defaultActionText),
onPressed: () => context.pop(true),
onPressed: () => Navigator.of(context).pop(true),
),
]
: <Widget>[
if (cancelActionText != null)
CupertinoDialogAction(
child: Text(cancelActionText),
onPressed: () => context.pop(false),
onPressed: () => Navigator.of(context).pop(false),
),
CupertinoDialogAction(
child: Text(defaultActionText),
onPressed: () => context.pop(true),
onPressed: () => Navigator.of(context).pop(true),
),
],
),
Expand Down

0 comments on commit 820bba9

Please sign in to comment.