type 'Future<dynamic>' is not a subtype of type 'ApplicationMeta'

69 views Asked by At

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

There are 1 answers

4
eeqk On

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: