0

I get this error 'type 'Future' is not a subtype of type 'ApplicationMeta'. I create a payment function. payment function type is future<List>. This function returns installedUpiapps in the list. I need to pass an argument to appWidget. But I get this error 'type 'Future' is not a subtype of type 'ApplicationMeta'.

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

class Homes extends StatelessWidget {
  payment() async {
  var appMetaList = await UpiPay.getInstalledUpiApplications();
    return appMetaList;
  }

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

@override
 Widget build(BuildContext context) {
   ApplicationMeta as = payment();
   return appWidget(as);
 }
}

1 Answers1

0

Once you add a return type to payment method you should see a compilation error.

payment is async, so it returns a Future. In order to build a widget with it, you have to use a FutureBuilder as described here https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html

FutureBuilder<List<ApplicationMeta>>(
  future: as
  builder: (context, snapshot) {
    // your widgets go here
  }
)

As for displaying a List of ApplicationMeta, have a look on these:

eeqk
  • 3,492
  • 1
  • 15
  • 22
  • Thanks for your reply.. I cannot create an instance for payment function because payment function return Future> but appWidget need ApplicationMeta type argument. I cannot pass the argument to appWidget. – Joshua Jenny Sibbu Jun 13 '21 at 13:14
  • can't really help you without understanding what's your program supposed to do, but if you want to display any instance of `ApplicationMeta` then just return `appMetaList.first` from `payment` – eeqk Jun 13 '21 at 14:51
  • I need to include google pay payment in my app. I found upi_pay pub package in pub dev. This package gives this error 'type 'Future' is not a subtype of type 'ApplicationMeta'. – Joshua Jenny Sibbu Jun 13 '21 at 15:10
  • I've updated the answer. If you have problem with changing method signature or creating a list of widgets, you may find completing a guide or two helpful: https://flutter.dev/docs/get-started/learn-more#flutter-basics – eeqk Jun 13 '21 at 15:21