drenther / upi_pay

Flutter plugin for UPI (Only in India)
MIT License
60 stars 71 forks source link

getInstalledUpiApplications return null #33

Closed joshuajennysibbu closed 3 years ago

joshuajennysibbu commented 3 years ago
      ═══════ Exception caught by widgets library ═══════════════════════════════════
         The following NoSuchMethodError was thrown building Homes(dirty):
         The getter 'upiApplication' was called on null.
         Receiver: null
         Tried calling: upiApplication

    import 'package:flutter/material.dart';
    import 'package:upi_pay/upi_pay.dart';

  class Homes extends StatelessWidget {
     Future<List<ApplicationMeta>> payment() async {
       final List<ApplicationMeta> appMetaList =
        await UpiPay.getInstalledUpiApplications();
return appMetaList;
   }

   Widget appWidget(appMeta) {
      ApplicationMeta aps = appMeta;

print(aps.upiApplication);

return Column(
  mainAxisAlignment: MainAxisAlignment.center,
  children: <Widget>[
    aps.iconImage(48), // Logo
    Container(
      margin: EdgeInsets.only(top: 4),
      alignment: Alignment.center,
      child: Text(
        aps.upiApplication.getAppName(),
        textAlign: TextAlign.center,
      ),
    ),
  ],
);

}

   @override
   Widget build(BuildContext context) {
    List<ApplicationMeta> vas;
    Future<List<ApplicationMeta>> as = payment();
    as.then((value) => () {
          vas = value;

] });

      return appWidget(vas);
    }
  }

getInstalledUpiApplications return null value.

reeteshranjan commented 3 years ago

The build method runs synchronously. Your call to payment is returning a Future, not a List<ApplicationMeta>. Please go through Flutter concepts and design your workflow such that the Future returned by payment method is completed and has returned the expected List<ApplicationMeta> variable for the build method to use to render your expected UI.

Looking at your usage/design in the above code, you can use FutureBuilder (see https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html) to get that going. That is by no means the only way to achieve that; but probably the most natural to Flutter apps.

Closing this bug with this.

joshuajennysibbu commented 3 years ago

The build method runs synchronously. Your call to payment is returning a Future, not a List<ApplicationMeta>. Please go through Flutter concepts and design your workflow such that the Future returned by payment method is completed and has returned the expected List<ApplicationMeta> variable for the build method to use to render your expected UI.

Looking at your usage/design in the above code, you can use FutureBuilder (see https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html) to get that going. That is by no means the only way to achieve that; but probably the most natural to Flutter apps.

Closing this bug with this.

Actually, forget to rename the title. My problem is UpiPay.getInstalledUpiApplications() return null. It does not show installed UPI apps.

reeteshranjan commented 3 years ago

It's very confusing with iterations of the problem statement changing. Please post the whole code and stack trace for clarity. Also, see if your problem matches #25 and comment here.

joshuajennysibbu commented 3 years ago
    import 'package:flutter/material.dart';
   import 'package:upi_pay/upi_pay.dart';

   class Homes extends StatelessWidget {
   Future<List<ApplicationMeta>> payment() async {
      final List<ApplicationMeta> appMetaList =
         await UpiPay.getInstalledUpiApplications();
      return appMetaList;
    }

   Widget appWidget(appMeta) {
     ApplicationMeta aps = appMeta;
      return Column(
      mainAxisAlignment: MainAxisAlignment.center,
         children: <Widget>[
          aps.iconImage(48), // Logo
          Container(
           margin: EdgeInsets.only(top: 4),
          alignment: Alignment.center,
            child: Text(
            aps.upiApplication.getAppName(),
             textAlign: TextAlign.center,
           ),
         ),
      ],
     );
   }

  @override
  Widget build(BuildContext context) {
     List<ApplicationMeta> vas;
     Future<List<ApplicationMeta>> as = payment();
       as.then((value) => () {
         vas = value;
          });

    return appWidget(vas);
   }
  }

This is my code.. I get this exception: the getter 'upiApplication' was called on null. Receiver: null Tried calling: upiApplication upiApplication return null.

reeteshranjan commented 3 years ago

As per my earlier comment, please rectify your code using FutureBuilder or an equivalent mechanism. You are getting this exception because variable aps is accessed in the build method call before your future has completed to populate aps with a valid non-null list.

joshuajennysibbu commented 3 years ago
 UpiPay.getInstalledUpiApplications().then((upiApps) {
       setState(() {
       this.upiApps = upiApps;
   });
  });
    print(upiApps);
   super.initState();

Even this code returns a null list

reeteshranjan commented 3 years ago

You are printing the upiApps app outside the then block. Please look at promises/futures concepts and reopen once you have done the right workflow at your end and still things don't work.

vaibhavcs99 commented 3 years ago

You are printing the upiApps app outside the then block. Please look at promises/futures concepts and reopen once you have done the right workflow at your end and still things don't work.

Future<List<ApplicationMeta>> getListOfApps() async { final applications = await UpiPay.getInstalledUpiApplications(); print(applications); return applications; } Even this is returning null

reeteshranjan commented 3 years ago

@vaibhavcs99 can you try to run the example app in my fork https://github.com/reeteshranjan/upi_pay and let us know if you see any applications there?

Also, which UPI payment apps have you configured with the bank account linked on your phone?

joshuajennysibbu commented 3 years ago

You are printing the upiApps app outside the then block. Please look at promises/futures concepts and reopen once you have done the right workflow at your end and still things don't work.

Future<List<ApplicationMeta>> getListOfApps() async { final applications = await UpiPay.getInstalledUpiApplications(); print(applications); return applications; } Even this is returning null

Yes, it still returns null.

joshuajennysibbu commented 3 years ago

@vaibhavcs99 can you try to run the example app in my fork https://github.com/reeteshranjan/upi_pay and let us know if you see any applications there?

Also, which UPI payment apps have you configured with the bank account linked on your phone?

It again return null.

reeteshranjan commented 3 years ago

@vaibhavcs99 can you try to run the example app in my fork https://github.com/reeteshranjan/upi_pay and let us know if you see any applications there? Also, which UPI payment apps have you configured with the bank account linked on your phone?

It again return null.

My comment mentioned two things: 1) run the example app and share observations, and 2) specify the payment apps configured to the point of setting up your bank account. Could you provide an answer accordingly?

reeteshranjan commented 3 years ago

You are printing the upiApps app outside the then block. Please look at promises/futures concepts and reopen once you have done the right workflow at your end and still things don't work.

Future<List<ApplicationMeta>> getListOfApps() async { final applications = await UpiPay.getInstalledUpiApplications(); print(applications); return applications; } Even this is returning null

Yes, it still returns null.

Please share your changed code.

joshuajennysibbu commented 3 years ago

You are printing the upiApps app outside the then block. Please look at promises/futures concepts and reopen once you have done the right workflow at your end and still things don't work.

Future<List<ApplicationMeta>> getListOfApps() async { final applications = await UpiPay.getInstalledUpiApplications(); print(applications); return applications; } Even this is returning null

Yes, it still returns null.

Please share your changed code.

  class Payment extends StatefulWidget {
  @override
  _PaymentState createState() => _PaymentState();
  }

 class _PaymentState extends State<Payment> {
  List<ApplicationMeta> apps;
  void initState() {
    super.initState();
   getListOfApps();
    }

   Future<List<ApplicationMeta>> getListOfApps() async {
    final applications = await UpiPay.getInstalledUpiApplications();
     print(applications);
     return applications;
    }

  @override
 Widget build(BuildContext context) {
    return Container();
 }
 }
reeteshranjan commented 3 years ago

You are printing the upiApps app outside the then block. Please look at promises/futures concepts and reopen once you have done the right workflow at your end and still things don't work.

Future<List<ApplicationMeta>> getListOfApps() async { final applications = await UpiPay.getInstalledUpiApplications(); print(applications); return applications; } Even this is returning null

Yes, it still returns null.

Please share your changed code.

  class Payment extends StatefulWidget {
  @override
  _PaymentState createState() => _PaymentState();
  }

 class _PaymentState extends State<Payment> {
  List<ApplicationMeta> apps;
  void initState() {
    super.initState();
   getListOfApps();
    }

   Future<List<ApplicationMeta>> getListOfApps() async {
    final applications = await UpiPay.getInstalledUpiApplications();
     print(applications);
     return applications;
    }

  @override
 Widget build(BuildContext context) {
    return Container();
 }
 }

Thanks! Please share the following:

  1. upi_pay package version used in your pubspec.yaml
  2. The UPI payment apps installed on your phone, that you have configured with your bank account.
  3. Your mobile phone OS and version.
drenther commented 3 years ago

@joshuajennysibbu For future context, please adhere to the issue template when raising a bug or feature request. It saves us from asking for information in iterative steps.

joshuajennysibbu commented 3 years ago

You are printing the upiApps app outside the then block. Please look at promises/futures concepts and reopen once you have done the right workflow at your end and still things don't work.

Future<List<ApplicationMeta>> getListOfApps() async { final applications = await UpiPay.getInstalledUpiApplications(); print(applications); return applications; } Even this is returning null

Yes, it still returns null.

Please share your changed code.

  class Payment extends StatefulWidget {
  @override
  _PaymentState createState() => _PaymentState();
  }

 class _PaymentState extends State<Payment> {
  List<ApplicationMeta> apps;
  void initState() {
    super.initState();
   getListOfApps();
    }

   Future<List<ApplicationMeta>> getListOfApps() async {
    final applications = await UpiPay.getInstalledUpiApplications();
     print(applications);
     return applications;
    }

  @override
 Widget build(BuildContext context) {
    return Container();
 }
 }

Thanks! Please share the following:

  1. upi_pay package version used in your pubspec.yaml
  2. The UPI payment apps installed on your phone, that you have configured with your bank account.
  3. Your mobile phone OS and version.
  1. I try with both pubspec.yaml package version number is upi_pay: ^1.0.1 and git link https://github.com/reeteshranjan/upi_pay. Both return null.
  2. I installed google pay and phone pe both are a link to a bank account.
  3. Realme3Pro version is android 10.
reeteshranjan commented 3 years ago

@joshuajennysibbu

  1. With 1.0.0 onward or my fork you can never get a null response. This version of upi_pay uses null safety syntax and returns a non-nullable List<ApplicationMeta>. So I would like to assume that you may be getting an empty list, which probably you are referring to as null.
  2. Please see the documentation of the getInstalledUpiApplications API to understand why you are not seeing your configured apps. Also see https://github.com/drenther/upi_pay#upi-apps-functional-status-dynamics, and APPS.md file for more detailed information.
reeteshranjan commented 2 years ago

Is https://github.com/drenther/upi_pay/issues/38 relevant and important for you?

If yes, could you please respond to my twitter thread with UPI and NPCI handles included in your response asking how these must be solved and how it helps you? https://twitter.com/reeteshr08/status/1488746633068089345

@vaibhavcs99 @joshuajennysibbu