Flutter 颤振Http调用列表<;t>;在UI中总是导致空值

Flutter 颤振Http调用列表<;t>;在UI中总是导致空值,flutter,Flutter,我在堆栈中尝试了很多示例,但仍然不知道我错过了哪个部分,UI中的结果总是显示为空 以下是我尝试的代码: class PointBallance { String id, date, datetime, companyid, storecode, customercode, topup, amount, remark, cashier, invoice ; PointBallance({this.id, this.date, this.datetime, this.companyid,

我在堆栈中尝试了很多示例,但仍然不知道我错过了哪个部分,UI中的结果总是显示为空

以下是我尝试的代码:

class PointBallance {

  String id, date, datetime, companyid, storecode, customercode, topup, amount, remark,  cashier, invoice ;
  PointBallance({this.id, this.date, this.datetime, this.companyid, this.storecode, this.customercode, this.topup, this.amount, this.remark, this.cashier, this.invoice});

 factory PointBallance.fromJson(Map<String, dynamic> json) {
   return PointBallance(
     id: json['id'],
     date: json['date'], 
     datetime: json['datetime'], 
     companyid: json['company_id'], 
     storecode: json['store_code'], 
     customercode: json['customer_code'], 
     topup: json['topup'], 
     amount: json['amount'], 
     remark: json['remark'], 
     cashier: json['cashier'], 
     invoice: json['invoice'], 
     );
 }
}


是否有正确显示数据结果的指南?因为在控制台中有结果。

您可以尝试更改
var bel=List.from(dtpoint.map((i)=>pointbalance.fromJson(i))
to
var bel=dtpoint.map((i)=>pointbalance.fromJson(i))将json输出作为问题中的文本。只有当你想在ui中显示一些无法用文字表达的东西时,才尝试使用图像。阅读:您有错误的json输出。请尝试更改它,而不是
[{Balance:{id:..}},…]
。或者您应该更改您的模型输出结果不是来自我方,而是来自第三方。@Kimfdirasdfasdf是正确的。在
pointbalance.fromJson
中查找
id
date
等。传递到此函数的根json对象没有这些字段。相反,它就像
余额:{id:180976,日期:2020-02-23,…}
。尝试将
dtpoint.map((i)=>pointbalance.fromJson(i))
更改为
dtpoint.map((i)=>pointbalance.fromJson(i[“Balance”])
Future<List<PointBallance>> pointBal() async {
       var url = 'http://someUrl';
       var res = await http.get(url);
       if(res.statusCode == 200) {
         var dtpoint = json.decode(res.body);
         print(dtpoint);
         var bel = List<PointBallance>.from(dtpoint.map((i) => PointBallance.fromJson(i)));
         return bel;
       } else {
          throw Exception(
         "Request to $url failed with status ${res.statusCode}: ${res.body}"
       );
       }
    }
class _PointScreenState extends State<PointScreen> {
  Future<List<PointBallance>> _point;
  AuthService _authService = new AuthService();

  @override
  void initState() {
    _point = _authService.pointBal();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My Point'),
      ),
      body: FutureBuilder<List<PointBallance>>(
          future: _point,
          builder: (context, snapshot) {
            if (snapshot.hasData) {
               var dt = snapshot.data[0].id;
              return Column(
                children: <Widget>[
                  **Text('in the top $dt'),**
                  Expanded(
                    child: ListView.builder(
                      itemCount: snapshot.data.length,
                      itemBuilder:(BuildContext context, int index){
                        var hei = snapshot.data[index];
                        return **Text(hei.id != null ? hei.id : 'Cant get data')**;
                      }),
                  ),
                ],
              );
            } else if (snapshot.hasError) {
              return Text('${snapshot.error}');
            }
            return CircularProgressIndicator();
          }),
    );
  }
} 
print(dtpoint);