show static method

Future<bool?> show(
  1. BuildContext context, {
  2. required String publishableApiKey,
  3. required String transactionId,
  4. List<MoosylPaymentSummaryItem>? items,
  5. bool isFullPage = true,
  6. bool isMasriviInBottomSheet = false,
  7. String? masriviPhoneNumber,
})

Opens the payment flow. Returns PaymentSuccess on success, null when closed without payment.

When items is supplied, the summary total is validated against the payment request amount.

Implementation

static Future<bool?> show(
  BuildContext context, {
  required String publishableApiKey,
  required String transactionId,
  List<MoosylPaymentSummaryItem>? items,
  bool isFullPage = true,
  bool isMasriviInBottomSheet = false,
  String? masriviPhoneNumber,
}) async {
  if (isFullPage) {
    return Navigator.push<bool?>(
      context,
      MaterialPageRoute<bool?>(
        builder: (ctx) => MoosylView(
          publishableApiKey: publishableApiKey,
          transactionId: transactionId,
          items: items,
          isFullPage: true,
          isMasriviInBottomSheet: isMasriviInBottomSheet,
          masriviPhoneNumber: masriviPhoneNumber,
          onBackPress: () => Navigator.pop(ctx, null),
          onPaymentSuccess: (payment) async {
            Navigator.pop(ctx, payment);
          },
        ),
      ),
    );
  } else {
    return showModalBottomSheet<bool?>(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (ctx) => DraggableScrollableSheet(
        initialChildSize: 0.9,
        minChildSize: 0.5,
        maxChildSize: 1,
        builder: (ctx, scrollController) => Container(
          decoration: const BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
          ),
          clipBehavior: Clip.antiAlias,
          child: MoosylView(
            publishableApiKey: publishableApiKey,
            transactionId: transactionId,
            items: items,
            isFullPage: false,
            isMasriviInBottomSheet: isMasriviInBottomSheet,
            masriviPhoneNumber: masriviPhoneNumber,
            onBackPress: () => Navigator.pop(ctx, null),
            onPaymentSuccess: (payment) async {
              Navigator.pop(ctx, payment);
            },
          ),
        ),
      ),
    );
  }
}