如何在Flutter中对JSON数据进行排序

如何在Flutter中对JSON数据进行排序

本文介绍了如何在Flutter中对JSON数据进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Json数据:

This is my Json data:

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"
}]

在我的应用中,我想在列表视图中显示日期为allocation_date = 2008-08-31的数据这是我在ListView中显示数据的代码:

In my app i want to show data in listview whose date is allocation_date=2008-08-31Here is my code for display data in 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']}')
                              ),
])))
}))
}}))])

我在Body()中调用了此方法:

I called this method in Body():

 body: Stack(
        children: <Widget>[
          ListView(
            children: <Widget>[
              callSummary(context,resultCheck2),
              todayCall(context,resultCheck3),
            ],
          ),
        ],
      ),

[现在在我的输出中以列表视图显示所有数据] [1]

[now in my output all data in list view ][1]

[1]: https://i.stack.imgur.com/B3VIz.png .show数据,其分配日期为2008-08-31

[1]: https://i.stack.imgur.com/B3VIz.png .show data whose allocation_date is 2008-08-31

推荐答案

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

You can create a filter icon above the listview, so you can use the date picker to select the date and based on the date you can filter the list and show it in your list view.

让我知道这是否对您有用.

let me know if this works for you.

谢谢

这篇关于如何在Flutter中对JSON数据进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 02:59