showCancelPaymentDialog function

Future<void> showCancelPaymentDialog(
  1. BuildContext context
)

Implementation

Future<void> showCancelPaymentDialog(BuildContext context) async {
  await showDialog(
    context: context,
    barrierDismissible: false,
    builder: (context) {
      if (Platform.isIOS) {
        // iOS style: Custom Cupertino-styled dialog
        return Center(
          child: CupertinoPopupSurface(
            child: Container(
              width: 300,
              padding: EdgeInsets.only(top: 15),
              decoration: BoxDecoration(
                color: CupertinoColors.systemBackground.resolveFrom(context),
                borderRadius: BorderRadius.circular(12),
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(
                    'Cancel Payment',
                    style: Theme.of(
                      context,
                    ).textTheme.titleMedium?.copyWith(fontSize: 17),
                  ),
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: 16),
                    child: Text(
                      'Are you sure you want to\n cancel payment?',
                      textAlign: TextAlign.center,
                      style: Theme.of(context).textTheme.bodySmall?.copyWith(
                        color: Colors.grey.shade600,
                      ),
                    ),
                  ),
                  const SizedBox(height: 16),
                  const Divider(height: 1, thickness: 0.5),
                  SizedBox(
                    height: 44,
                    child: Row(
                      children: [
                        Expanded(
                          child: CupertinoButton(
                            padding: EdgeInsets.zero,
                            onPressed: () => Navigator.of(context).pop(),
                            child: const Text(
                              'No',
                              style: TextStyle(
                                color: CupertinoColors.activeBlue,
                                fontSize: 16,
                              ),
                            ),
                          ),
                        ),
                        Container(
                          width: 0.5,
                          height: 44,
                          color: CupertinoColors.separator.resolveFrom(context),
                        ),
                        Expanded(
                          child: CupertinoButton(
                            padding: EdgeInsets.zero,
                            onPressed: () {
                              Navigator.of(context).pop();
                              Navigator.of(context, rootNavigator: true).pop(
                                HmaroPayPaymentResult(
                                  error: "Payment Cancelled",
                                ),
                              );
                            },
                            child: const Text(
                              'Yes',
                              style: TextStyle(
                                color: CupertinoColors.destructiveRed,
                                fontSize: 16,
                                fontWeight: FontWeight.w600,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      } else {
        return Dialog(
          backgroundColor: Colors.white,
          shape: RoundedRectangleBorder(),
          child: Padding(
            padding: EdgeInsets.only(top: 20, bottom: 5),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                Padding(
                  padding: const EdgeInsets.only(left: 20.0),
                  child: Text(
                    'Are you sure you want to cancel?',
                    style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    TextButton(
                      onPressed: () => Navigator.of(context).pop(false),
                      child: const Text(
                        'No',
                        style: TextStyle(color: Colors.red),
                      ),
                    ),
                    const SizedBox(width: 8),
                    TextButton(
                      onPressed: () {
                        Navigator.of(context).pop();
                        Navigator.of(context, rootNavigator: true).pop(
                          HmaroPayPaymentResult(error: "Payment Cancelled"),
                        );
                      },
                      child: const Text(
                        'Yes',
                        style: TextStyle(color: Colors.green),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        );
      }
    },
  );
}