Flutter-v3 icon indicating copy to clipboard operation
Flutter-v3 copied to clipboard

Screen Reloads When you Tap on the Input Fields

Open ComputerMaverick69 opened this issue 2 years ago • 4 comments

Description

The UI reloads each time i tap on it to put it the card details. This happens with all of the input fields on the package, except the drop-downs.

Steps to Reproduce

  1. Implement flutterwave_standard: ^1.0.6
  2. Pass the required parameters
  3. Select Payment Method and Tap

Expected behaviour: It should allow for users to input their card details

Actual behaviour:

UI reloads

Reproduces how often:

All the time!

Configuration

  • API Version: v3
  • Environment: Test Mode
  • Device: iPhone 11 Pro Simulator - iOS 15.5
  • Language: Dart
  • Flutter Version: 3.3.3

Additional Information

Flutterwave Payment Implementation Code

//Flutterwave payment implementation
  Future<void> payUsingFlutterwave(
      context,
      String currency,
      double amount,
      String email,
      String phone,
      String pkey,
      String skey,
      String enckey,
      String name,
      String ref) async {
    final Customer customer =
        Customer(name: name, phoneNumber: phone, email: email);

    final Flutterwave flutterwave = Flutterwave(
        context: context,
        publicKey: pkey,
        currency: currency,
        txRef: ref,
        amount: amount.toString(),
        customer: customer,
        paymentOptions: "ussd, card, barter, payattitude",
        customization: Customization(title: "Pay using Flutterwave"),
        isTestMode: true,
        redirectUrl: "/");

    final ChargeResponse response = await flutterwave.charge();
    if (response != null) {
      // print("${response.toJson()}");
      if (response.success!) {
        Future<ResponseModel> verifyFunds(String txnId, String token) async {
          late ResponseModel responseModel;
          //var dio = Dio();
          // print(txnId);

          try {
            var response = await Dio().get(
              'https://api.flutterwave.com/v3/transactions/${txnId}/verify',
              options: Options(headers: {
                "Content-Type": "application/json",
                "Authorization": "Bearer ${token}",
              }),
            );

            if (response.statusCode.toString() == '200' ||
                response.statusMessage.toString() == 'OK') {
              print('Transaction Verified');
              responseModel = ResponseModel(true, 'Funds Verified');
            } else {
              responseModel = ResponseModel(false, response.statusMessage!);
            }
          } catch (e) {
            print("Error caught " + e.toString());
          }
          // print(responseModel.isSuccess.toString());
          return responseModel;
        }

        // Call the verify transaction endpoint with the transactionID returned in `response.transactionId` to verify transaction before offering value to customer
        if (response.status == 'success' && response.success == true) {
          verifyFunds(response.transactionId!, skey).then((status) {
            if (status.isSuccess) {
              Get.snackbar("Payments", 'Payment Confirmed');
              _isPaymentConfirmed = true;
              update();
            } else {
              Get.snackbar(
                  'Payments', 'Payment Cannot be Confirmed at this Time!');
              // print('Transaction Could not be verified!');
            }
          });
        } else {}
      } else {
        // Transaction not successful
        Get.snackbar('Payments', 'Payments Failed!');
      }
    } else {}
  }

Page Calling the Implementation

import 'package:demo/controllers/payments/payment_controller.dart';
import 'package:demo/controllers/users/user_controller.dart';
import 'package:demo/helpers/app_styles.dart';
import 'package:demo/helpers/size_config.dart';
import 'package:demo/models/payments/payment_methods_model.dart';
import 'package:demo/widgets/center_loader_widget.dart';
import 'package:demo/widgets/title_text_widget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:uuid/uuid.dart';

class PaymentMethodsScreen extends StatelessWidget {
  final int? id;
  final int? qty;
  final double amount;
  final double? discount;
  final String? title;
  final double? charges;
  final String? date;
  final String? time;
  final String? address;
  final String? lat;
  final String? lng;

  PaymentMethodsScreen(
      {Key? key,
      this.id,
      this.qty,
      required this.amount,
      this.discount,
      this.title,
      this.charges,
      this.date,
      this.time,
      this.address,
      this.lat,
      this.lng})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PaymentsController>(builder: (paymentMethodsController) {
      return Scaffold(
        appBar: AppBar(
          title: TitleTextWidget(
            titleText: 'Payments',
            titleColor: AppStyles.appPrimaryColor,
          ),
          leading: GestureDetector(
            onTap: () {
              Get.back();
            },
            child: const Icon(Icons.arrow_back_outlined,
                color: AppStyles.appPrimaryColor),
          ),
          backgroundColor: Colors.white,
          elevation: 0,
        ),
        backgroundColor: Colors.white,
        body: paymentMethodsController.isLoaded
            ? Container(
                padding: EdgeInsets.all(SizeConfig.height10),
                height: double.maxFinite,
                child: ListView.builder(
                    itemCount: paymentMethodsController.paymentMethods.length,
                    itemBuilder: (context, index) {
                      return Get.previousRoute == '/PremiumPricingModal' &&
                              index == 0
                          ? Container()
                          : _buildPaymentListItem(context, index,
                              paymentMethodsController.paymentMethods[index]);
                    }),
              )
            : CenterLoaderWidget(),
      );
    });
  }

  Widget _buildPaymentListItem(
      BuildContext context, int position, Data paymentMethod) {
    var controller = Get.find<PaymentsController>();
    var userController = Get.find<UserController>();

    return GestureDetector(
      onTap: () {
        if (paymentMethod.title!.toLowerCase().split(' ').contains('cash')) {
          print('Cash');
        } else if (paymentMethod.title!
            .toLowerCase()
            .split(' ')
            .contains('flutterwave')) {
          //call flutterwave payment method from controller
          controller.payUsingFlutterwave(
            context, 
            'NGN', 
            amount, 
            userController.userModel.data!.email, 
            userController.userModel.data?.phone ?? '',
            paymentMethod.appPublicKey.toString(), 
            paymentMethod.appSecretKey.toString(), 
            paymentMethod.encryptionKey.toString(), 
            userController.userModel.data!.name, 
            Uuid().v1()
          );
        }
      },
      child: Padding(
        padding: EdgeInsets.symmetric(
            horizontal: SizeConfig.width30, vertical: SizeConfig.height10),
        child: Container(
          width: SizeConfig.width250,
          height: SizeConfig.height70,
          padding: EdgeInsets.symmetric(horizontal: SizeConfig.width20),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(SizeConfig.radius15),
              border: Border.all(width: 2, color: AppStyles.appPrimaryColor)),
          child: Center(
              child: TitleTextWidget(
                  titleText: paymentMethod.title!,
                  titleColor: AppStyles.appPrimaryColor)),
        ),
      ),
    );
  }
}

ComputerMaverick69 avatar Nov 17 '22 11:11 ComputerMaverick69