Flutter 如何在flatter中对json数据进行排序?

Flutter 如何在flatter中对json数据进行排序?,flutter,dart,Flutter,Dart,这是我的Json数据: call_record: [ { "machine_location":"Restaurant", "allocation_date:"2008-08-31" "status":"C", "customer_address":"pune" } { "machine_location":"Restaurant", "allocation_date:"2008-08-31" "status":"N", "customer_address":"pune" } { "machin

这是我的Json数据:

call_record: [
{
"machine_location":"Restaurant",
"allocation_date:"2008-08-31"
"status":"C",
"customer_address":"pune"
}
{
"machine_location":"Restaurant",
"allocation_date:"2008-08-31"
"status":"N",
"customer_address":"pune"
}
{
"machine_location":"Restaurant",
"allocation_date:"2008-08-31"
"status":"O",
"customer_address":"pune"
}]
在我的应用程序中,我想在listview中显示日期为分配的数据 以下是我在ListView中显示数据的代码:

    Widget todayCall(BuildContext context,resultCheck3){
          return Container(
           child: Column(
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Container(
                        child:Text("Today's Calls"),
                      ),
                    ],
                  ),
                    FutureBuilder(
                      future: api3,
                     builder: (context,snapshot){
                     if (snapshot.data != null) {
                      return Container(
                      child: ListView.builder(
                      itemCount: snapshot.data.length,
                      itemBuilder: (BuildContext conxt, int index) {
                      return Card(
                      child: Padding(
                      child: ExpansionTile(
                      title: Text('${snapshot.data[index]['customer_name']}') 
                      subtitle: Text('${snapshot.data[index]   ['error_message']}'"\n"'${snapshot.data[index]['allocation_date']}'
                              trailing: Icon(Icons.arrow_drop_down,size: 30.0,
                              children: <Widget>[
                              ListTile(
                              title: Text("Machine Model",style: TextStyle(fontSize:13)),
                              subtitle: Text('${snapshot.data[index]['machine_type']}')
                              ),
                              ListTile(
                              title: Text("Location",style: TextStyle(fontSize:13)),
                              subtitle: Text('${snapshot.data[index]['location_address']}')
                              ),
])))
}))
}}))])
Widget今日调用(BuildContext上下文,resultCheck3){
返回容器(
子:列(
儿童:[
划船(
儿童:[
容器(
孩子:文本(“今天的电话”),
),
],
),
未来建设者(
未来:api3,
生成器:(上下文,快照){
如果(snapshot.data!=null){
返回容器(
子项:ListView.builder(
itemCount:snapshot.data.length,
itemBuilder:(BuildContext-conxt,int-index){
回程卡(
孩子:填充(
子文件:扩展文件(
标题:文本(“${snapshot.data[index]['customer_name']}”)
字幕:文本(${snapshot.data[index]['error_message']}'”\n“${snapshot.data[index]['allocation_date']}”
尾随:图标(图标。箭头下拉,大小:30.0,
儿童:[
列表砖(
标题:文本(“机器型号”,样式:TextStyle(fontSize:13)),
字幕:文本(“${snapshot.data[index][machine_type']}”)
),
列表砖(
标题:文本(“位置”,样式:TextStyle(fontSize:13)),
字幕:文本(“${snapshot.data[index]['location\u address']}”)
),
])))
}))
}}))])
我在Body()中调用了此方法:

body:Stack(
儿童:[
列表视图(
儿童:[
callSummary(上下文,结果检查2),
todayCall(上下文,resultCheck3),
],
),
],
),
[现在在我的列表视图中输出所有数据][1]


[1] :.显示分配日期为2008-08-31的数据在future builder中返回小部件之前,您可以检查是否满足日期条件

if (snapshot.data != null) {
                      return Container(
                      child: ListView.builder(
                      itemCount: snapshot.data.length,
                      itemBuilder: (BuildContext conxt, int index) {
                      if(snapshot.data[index]['allocation_date'] == '2008-08-31'){
                        return Card(.....
                        .
                        .
                        .
                      else{
                        return Container(height: 0); //return a container with zero height in the else case because you cant return a null and your return must be a widget
                      }
                        .
                        .
                        .

您可以在列表视图上方创建一个过滤器图标,以便使用日期选择器选择日期,并根据日期筛选列表并在列表视图中显示

让我知道这是否适合你

谢谢

if (snapshot.data != null) {
                      return Container(
                      child: ListView.builder(
                      itemCount: snapshot.data.length,
                      itemBuilder: (BuildContext conxt, int index) {
                      if(snapshot.data[index]['allocation_date'] == '2008-08-31'){
                        return Card(.....
                        .
                        .
                        .
                      else{
                        return Container(height: 0); //return a container with zero height in the else case because you cant return a null and your return must be a widget
                      }
                        .
                        .
                        .