【问题标题】:I have List<ApplicationMeta> i need to convert ApplicationMeta type我有 List<ApplicationMeta> 我需要转换 ApplicationMeta 类型
【发布时间】:2021-08-31 18:39:40
【问题描述】:
List<ApplicationMeta> apps = [];
@override
void initState() {
 UpiPay.getInstalledUpiApplications().then((value) {
  setState(() {
    this.apps = value;
    print('successfully append');
  });
}).catchError((e) {
  print('im in error part');
});
super.initState();
}

这个程序是关于 getupiapplications 的。 getInstalledUpiApplications() 函数返回“列表”,但我已转换为 ApplicationMeta。我有错误。

【问题讨论】:

  • 您无法将 List 转换为类。请说明您要达到的目标是什么?

标签: flutter flutter-futurebuilder flutter-future


【解决方案1】:
apps.forEach((app) => {
//do whatever with app
print(app.name); //or whatever
})

在上面的代码中,app 的类型为 ApplicationMeta forEach 将允许您遍历列表 apps 中的每个 app。您的问题不清楚,但您似乎想通过List迭代

【讨论】:

    【解决方案2】:

    感谢回复它的工作,但我面临另一个问题。我得到空值。这是我的代码

    import 'package:flutter/material.dart';
    import 'package:upi_pay/upi_pay.dart';
    
    class Homes extends StatefulWidget {
     @override
     _HomesState createState() => _HomesState();
     }
    
      class _HomesState extends State<Homes> {
        List<ApplicationMeta> apps = [];
    
     @override
     void initState() {
       super.initState();
       UpiPay.getInstalledUpiApplications().then((value) {
       setState(() {
        this.apps = value;
        print('completed');
        });
        });
       }
    
    
      Widget cons() {
       return Container(
      color: Colors.black,
      child: Stack(children: [
        ListView.builder(
            itemCount: apps.length,
            itemBuilder: (buildContext, int i) {
              print(apps[i]);
              return apps[i].iconImage(48);
            })
         ]),
         );
        }
    
     @override
      Widget build(BuildContext context) {
      return cons();
      }
      }
    

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多