Flutter 如何修复颤振中列表中未显示的it数据

Flutter 如何修复颤振中列表中未显示的it数据,flutter,Flutter,我想显示一个数据列表来解析JSON,我已经编写了所有代码,但是数据没有显示在listview中,我不明白我的代码中的错误是什么。我正在分享我的代码。请建议我 这就是我解析的JSON [ { “客户名称”:“里奇谷,里奇谷学校”, “手机”:“9796005602”, “产品id”:“47265”, “imei”:“868004027863425”, “序列号”:“2016172679”, “名称”:“L-100[2G]”, “id”:“36”, “投诉编号”:“11212”, “投诉id”:“C

我想显示一个数据列表来解析JSON,我已经编写了所有代码,但是数据没有显示在listview中,我不明白我的代码中的错误是什么。我正在分享我的代码。请建议我

这就是我解析的JSON

[ { “客户名称”:“里奇谷,里奇谷学校”, “手机”:“9796005602”, “产品id”:“47265”, “imei”:“868004027863425”, “序列号”:“2016172679”, “名称”:“L-100[2G]”, “id”:“36”, “投诉编号”:“11212”, “投诉id”:“CMP/160720/11211”, “故障”:“设备未显示\n”, “手机号码”:“5756200501797”, “客户产品id”:“10514”, “kyc_id”:空, “车辆编号”:“HR55R0561” } ]

这是我的密码

import 'package:deviceinstallation/complaint.dart';
import 'package:deviceinstallation/ordercountdetail.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
import 'dashboard_screen.dart';
import 'model/complaint_count_model.dart';

//void main()=> runApp(ComplaintCountDetails());

class ComplaintCountDetails  extends StatelessWidget{
  String cID;
  ComplaintCountDetails(this.cID);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    print("id"+cID);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: "FLutter Demo",
      theme: ThemeData(
          primarySwatch: Colors.blue
      ),
      home: ComplaintCountDetailsScreen(cID: cID,),
    );

  }
}

class ComplaintCountDetailsScreen extends StatefulWidget {
  //final String title;
  String cID;
  //ComplaintCountDetailsScreen({this.cID});
  ComplaintCountDetailsScreen({Key key, this.cID}): super(key: key);

  @override
  ComplaintCountStates createState() => ComplaintCountStates(cID);
}

class ComplaintCountStates extends State<ComplaintCountDetailsScreen> {
  Icon cusIcon =Icon(Icons.search);
  Widget cusSearchBar= Text("Complaint List");
  String cID;
  ComplaintCountStates(this.cID);
  String sUrl= "https://fasttracksoft.us/api_v2/device_installation/";
  bool isLoading= false;
  List<ComplaintCountDetailModel> complaintCountList;
  Future<List<ComplaintCountDetails>> getComplaintCountList()async{
    setState(() {
      isLoading=true;
    });
     final prefs= await SharedPreferences.getInstance();
      var params= "complaindetail.php?id="+prefs.getString('id')+"&cid="+cID;
     // print("param:"+params);
     try{
       var response= await http.get(sUrl+params);
       print("sURL:"+sUrl);
       print("param:"+params);
      // print("response+url_param:$response");
       print("customerID:"+prefs.getString('id'));
       print("url+params:"+sUrl+params);

       if(response.statusCode==200){
         complaintCountList=complaintCountDetailModelFromJson(response.body);
         print("listJSON:"+complaintCountList.toString());
         print(complaintCountList[0].toString());
         if(complaintCountList!=null){
           setState(() {
             isLoading=false;
           });
         }
       }
     }catch(e){
       //return complaintCountList;
     }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    setState(() {
      isLoading=true;
      getComplaintCountList();
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: Colors.white),
          onPressed: (){
            Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => ComplaintScreen()),
            );
          },
        ),
        title: cusSearchBar,
        actions: <Widget>[
          IconButton(
            //tooltip: 'Search',
            //icon: const Icon(Icons.search),
            //Don't block the main thread
            onPressed: () {
              setState(() {
                if(this.cusIcon.icon==Icons.search){
                  this.cusIcon=Icon(Icons.cancel);
                  this.cusSearchBar=TextField(
                    textInputAction: TextInputAction.go,
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: "Search here",
                    ),
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 16.0,
                    ),
                  );
                }else{
                  this.cusIcon =Icon(Icons.search);
                  this.cusSearchBar= Text("AppBar");
                }
              });
            },
            icon: cusIcon,
          ),
        ],
      ),
      body:SafeArea(
          child: Column(
              children: <Widget>[
                Container(
                  padding: const EdgeInsets.fromLTRB(0.0, 5.0, 5.0, 0.0),
                  height: MediaQuery.of(context).size.height / 15.2,
                  width: MediaQuery.of(context).size.width * 15.5,
                 // color: Colors.teal,
                  child: Text("Customer Name :",
                  style: TextStyle(
                    fontSize: 25.0,
                    fontWeight: FontWeight.bold,
                    color: Colors.teal

                  ),),
                ),
                Container(
                  padding: const EdgeInsets.fromLTRB(0.0, 5.0, 5.0, 0.0),
                  height: MediaQuery.of(context).size.height / 15.2,
                  width: MediaQuery.of(context).size.width * 15.5,
                //  color: Colors.teal,
                  child:  Text("Complaint List for Engineer",
                    style: TextStyle(
                      fontStyle: FontStyle.italic,
                      fontSize: 20.0,
                      color: Colors.teal,
                      fontWeight: FontWeight.bold
                    ),),
                ),
                Visibility(
                    maintainSize: true,
                    maintainAnimation: true,
                    maintainState: true,
                    visible: isLoading,
                    child: Container(
                      child: CircularProgressIndicator(),
                    )),
                Expanded(
                    child: ListView.builder(
                        itemCount: null==complaintCountList ? 0:complaintCountList.length,
                        itemBuilder: (BuildContext context, index){
                          ComplaintCountDetailModel countModel= complaintCountList[index];
                          return Container(
                            child: Padding(
                              padding: const EdgeInsets.only(top: 0.0, bottom: 0.0, left: 5.0, right: 5.0),
                              child: Card(
                                child: Container(
                                  padding: const EdgeInsets.only(top: 10.0, bottom: 10.0, left: 15.0, right: 15.0),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.stretch,
                                    mainAxisSize: MainAxisSize.max,
                                    //crossAxisAlignment: CrossAxisAlignment.start,
                                    children: <Widget>[
                                      Text('IMEI :'+countModel.imei,
                                        style: TextStyle(
                                          //fontSize: 20.0,
                                          color: Colors.green,
                                          fontWeight: FontWeight.bold,
                                          // backgroundColor: Colors.green
                                        ),
                                      ),
                                      Text('Complaint ID :'+countModel.id,
                                        style: TextStyle(
                                          // fontSize: 20.0,
                                          color: Colors.black,
                                          // backgroundColor: Colors.green
                                        ),
                                      ),
                                      Text('Serial No :'+countModel.serialNo,
                                        style: TextStyle(
                                          //fontSize: 20.0,
                                          color: Colors.black,
                                          // backgroundColor: Colors.green
                                        ),
                                      ),
                                      Text('Customer Name :'+countModel.customerName,
                                        style: TextStyle(
                                          //fontSize: 20.0,
                                          color: Colors.black,
                                          // backgroundColor: Colors.green
                                        ),
                                      ),
                                      Text('Mobile :'+countModel.mobile,
                                        style: TextStyle(
                                          //fontSize: 20.0,
                                          color: Colors.black,
                                          // backgroundColor: Colors.green
                                        ),
                                      ),
                                      Text('Device Model :'+countModel.productId,
                                        style: TextStyle(
                                          // fontSize: 20.0,
                                          color: Colors.black,
                                          // backgroundColor: Colors.green
                                        ),
                                      ),

                                      Text('Vehicle No :'+countModel.vehicleNo,
                                        style: TextStyle(
                                          //fontSize: 20.0,
                                          color: Colors.black,
                                          // backgroundColor: Colors.green
                                        ),
                                      ),
                                      Text('Complaint issue :'+countModel.fault,
                                        style: TextStyle(
                                          //fontSize: 20.0,
                                          color: Colors.black,
                                          // backgroundColor: Colors.green
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ),
                          );
                        }
                    ))
              ],
          ))
    );
  }
}
import'程序包:设备安装/投诉.dart';
导入“package:deviceinstallation/ordercountdetail.dart”;
进口“包装:颤振/cupertino.dart”;
进口“包装:颤振/材料.省道”;
导入“package:shared_preferences/shared_preferences.dart”;
将“package:http/http.dart”导入为http;
导入“dashboard_screen.dart”;
导入“模型/投诉计数模型.dart”;
//void main()=>runApp(ComplaintCountDetails());
类ComplaintCountDetails扩展了无状态小部件{
字符串cID;
ComplaintCountDetails(this.cID);
@凌驾
小部件构建(构建上下文){
//TODO:实现构建
打印(“id”+cID);
返回材料PP(
debugShowCheckedModeBanner:false,
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色
),
主页:ComplaintCountDetailsScreen(cID:cID,),
);
}
}
类ComplaintCountDetailsScreen扩展StatefulWidget{
//最后的字符串标题;
字符串cID;
//ComplaintCountDetailsScreen({this.cID});
ComplaintCountDetailsScreen({Key-Key,this.cID}):super(Key:Key);
@凌驾
ComplaintCountState createState()=>ComplaintCountState(cID);
}
类ComplaintCountState扩展状态{
图标cusIcon=图标(Icons.search);
Widget cusSearchBar=文本(“投诉列表”);
字符串cID;
投诉国家(this.cID);
字符串sUrl=”https://fasttracksoft.us/api_v2/device_installation/";
bool isLoading=false;
投诉名单;
未来的getComplaintCountList()异步{
设置状态(){
isLoading=true;
});
final prefs=wait SharedPreferences.getInstance();
var params=“complindetail.php?id=“+prefs.getString('id')+”&cid=“+cid;
//打印(“参数:”+params);
试一试{
var response=wait http.get(sUrl+params);
打印(“sURL:+sURL”);
打印(“参数:”+params);
//打印(“响应+url参数:$response”);
打印(“customerID:+prefs.getString('id'));
打印(“url+params:+sUrl+params”);
if(response.statusCode==200){
complaintCountList=complaintCountDetailModelFromJson(response.body);
打印(“listJSON:+complaintCountList.toString());
打印(complaintCountList[0].toString());
if(complaintCountList!=null){
设置状态(){
isLoading=false;
});
}
}
}捕获(e){
//返回投诉清单;
}
}
@凌驾
void initState(){
//TODO:实现initState
super.initState();
设置状态(){
isLoading=true;
getComplaintCountList();
});
}
@凌驾
小部件构建(构建上下文){
//TODO:实现构建
返回脚手架(
appBar:appBar(
领先:IconButton(
图标:图标(Icons.arrow\u back,颜色:Colors.white),
已按下:(){
导航器。推(
上下文
MaterialPage路由(生成器:(上下文)=>ComplaintScreen()),
);
},
),
标题:库斯切巴,
行动:[
图标按钮(
//工具提示:“搜索”,
//图标:常量图标(Icons.search),
//不要阻塞主线程
已按下:(){
设置状态(){
if(this.cusIcon.icon==Icons.search){
this.cusIcon=Icon(Icons.cancel);
this.cusSearchBar=TextField(
textInputAction:textInputAction.go,
装饰:输入装饰(
边框:InputBorder.none,
hintText:“在此处搜索”,
),
样式:TextStyle(
颜色:颜色,白色,
字体大小:16.0,
),
);
}否则{
this.cusIcon=Icon(Icons.search);
this.cusSearchBar=文本(“AppBar”);
}
});
},
图标:cusIcon,
),
],
),
正文:安全区(
子:列(
儿童:[
容器(
填充:LTRB(0.0,5.0,5.0,0.0)中的常数边集,
高度:MediaQuery.of(context).size.height/15.2,
宽度:MediaQuery.of(context).size.width*15.5,
//颜色:Colors.teal,
子项:文本(“客户名称:”,
样式:TextStyle(
字体大小:25.0,
fontWeight:fontWeight.bold,
颜色:Colors.teal
),),
),
容器(
填充:LTRB(0.0,5.0,5.0,0.0)中的常数边集,
高度:MediaQuery.of(context).size.height/15.2,
宽度:MediaQuery.of(context).size.width*15.5,
//颜色:Colors.teal,
子项:文本(“工程师投诉清单”,
样式:TextStyle(
fontStyle:fontStyle.italic,
字体大小:20.0,
颜色:Colors.teal,
fontWeight:fontWeight.bold
),),
),
可见度(
尺寸:对,
维护动画
    List<DecoderClass> decoderClassFromJson(String str) => 

    List<DecoderClass>.from(json.decode(str).map((x) => DecoderClass.fromJson(x)));
    
    String decoderClassToJson(List<DecoderClass> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
    
    class DecoderClass {
        DecoderClass({
            this.customerName,
            this.mobile,
            this.productId,
            this.imei,
            this.serialNo,
            this.name,
            this.id,
            this.complainNo,
            this.complainId,
            this.fault,
            this.mobileNo,
            this.customerProductId,
            this.kycId,
            this.vehicleNo,
        });
    
        final String customerName;
        fina

l String mobile;
    final String productId;
    final String imei;
    final String serialNo;
    final String name;
    final String id;
    final String complainNo;
    final String complainId;
    final String fault;
    final String mobileNo;
    final String customerProductId;
    final dynamic kycId;
    final String vehicleNo;

    factory DecoderClass.fromJson(Map<String, dynamic> json) => DecoderClass(
        customerName: json["customer_name"],
        mobile: json["mobile"],
        productId: json["product_id"],
        imei: json["imei"],
        serialNo: json["serial_no"],
        name: json["name"],
        id: json["id"],
        complainNo: json["complain_no"],
        complainId: json["complain_id"],
        fault: json["fault"],
        mobileNo: json["mobile_no"],
        customerProductId: json["customer_product_id"],
        kycId: json["kyc_id"],
        vehicleNo: json["vehicle_no"],
    );

    Map<String, dynamic> toJson() => {
        "customer_name": customerName,
        "mobile": mobile,
        "product_id": productId,
        "imei": imei,
        "serial_no": serialNo,
        "name": name,
        "id": id,
        "complain_no": complainNo,
        "complain_id": complainId,
        "fault": fault,
        "mobile_no": mobileNo,
        "customer_product_id": customerProductId,
        "kyc_id": kycId,
        "vehicle_no": vehicleNo,
    };
}
  Future<DecoderClass> _future;
  Future<DecoderClass> getData() async {
    final http.Response response = await http.get(
        'https://fasttracksoft.us/api_v2/device_installation/',
        );

    if (response.statusCode < 200 ||
        response.statusCode > 400 ||
        json == null) {
      throw new Exception("Error while fetching data");
    } else {
      return DecodeClass.fromJson(json.decode(response.body));
    }
  }
  @override
void initState() {
super.initState();
_future = getData();
}
FutureBuilder<DecodeClass>(
    future: _future,
    builder: (context, snapshot) {
   return ListView.builder(
                  shrinkWrap: true,
                  itemBuilder: (context, i) {})})