flutter [“数据”示例,“数据”示例]

vc9ivgsu  于 2023-02-05  发布在  Flutter
关注(0)|答案(1)|浏览(148)

我正试图从API过滤数据,我在API 1)正在进行2)即将到来的3个类别和3)过去。我想过滤所有三类点击事件的差异差异按钮。请找到下面提到的代码和细节。
以下是空气污染指数的回应:

{
  "status": true,
  "result": "found",
  "data": [
    {
      "ref_id": "73",
      "postId": "106764933065187174744",
      "azakhana_name": "sakina baugh",
      "city_name": "rajula",
      "description": "djsjjsje",
      "end_date": "31-01-2023",
      "image_path": "Posts_Images\/POST-IMG106843982.jpg",
      "name_of_schollar": "Yasin Rajani",
      "postDateTime": "19-01-2023 12:22 PM",
      "program_list": "Majlis",
      "special_notes": "bsjsisjs",
      "start_date": "31-01-2023",
      "time": "3:30 PM",
      "user_name": "Taki Rajani",
      "status": "Upcoming"
    },
    {
      "ref_id": "71",
      "postId": "106764933065187174744",
      "azakhana_name": "Shanti baugh",
      "city_name": "Mahuva",
      "description": "No",
      "end_date": "31-01-2023",
      "image_path": "Posts_Images\/POST-IMG471193454.jpg",
      "name_of_schollar": "Molana ",
      "postDateTime": "18-01-2023 12:28 PM",
      "program_list": "Majlis",
      "special_notes": "No",
      "start_date": "18-01-2023",
      "time": "12:28 PM",
      "user_name": "Taki Rajani",
      "status": "Ongoing"
    },
    {
      "ref_id": "72",
      "postId": "106764933065187174744",
      "azakhana_name": "hussiani hall ",
      "city_name": "Mahuva ",
      "description": "jsjsisjw",
      "end_date": "31-01-2023",
      "image_path": "Posts_Images\/POST-IMG1564452985.jpg",
      "name_of_schollar": "yes soon",
      "postDateTime": "19-01-2023 12:21 PM",
      "program_list": "Majlis",
      "special_notes": "sjsis8sisjsj",
      "start_date": "17-01-2023",
      "time": "12:20 PM",
      "user_name": "Taki Rajani",
      "status": "Ongoing"
    }
  ],
  "totalPosts": "3",
  "totalPages": 1,
  "perPageLimit": 3,
  "currentPage": 1,
  "hasNextPage": 0
}

我在我的应用程序中有一个按钮,名称是数据过滤器。我正在使用where方法从api过滤数据,但它给我错误,如数据示例。
以下代码用于筛选数据:

var _status = snapshot.data!.data!.where((e) => e.status == "Upcoming").toList();
print(_status);

错误:I/ Flutter (21212):[“数据”示例,“数据”示例]

iqjalb3h

iqjalb3h1#

import 'dart:convert';
Future<void> main() async {
  var body = await getData();
  var _status = body['data'].where((e) => e['status'] == "Upcoming").toList();

  for (var element in _status) {
    print(element);
  }
}

// for demo usage of future, async and await. Or api call.
Future getData() async {
   String jsons = await '''{
    "status": true,
    "result": "found",
    "data": [
      {
        "ref_id": "73",
        "postId": "106764933065187174744",
        "azakhana_name": "sakina baugh",
        "city_name": "rajula",
        "description": "djsjjsje",
        "end_date": "31-01-2023",
        "image_path": "Posts_Images\/POST-IMG106843982.jpg",
        "name_of_schollar": "Yasin Rajani",
        "postDateTime": "19-01-2023 12:22 PM",
        "program_list": "Majlis",
        "special_notes": "bsjsisjs",
        "start_date": "31-01-2023",
        "time": "3:30 PM",
        "user_name": "Taki Rajani",
        "status": "Upcoming"
      },
      {
        "ref_id": "71",
        "postId": "106764933065187174744",
        "azakhana_name": "Shanti baugh",
        "city_name": "Mahuva",
        "description": "No",
        "end_date": "31-01-2023",
        "image_path": "Posts_Images\/POST-IMG471193454.jpg",
        "name_of_schollar": "Molana ",
        "postDateTime": "18-01-2023 12:28 PM",
        "program_list": "Majlis",
        "special_notes": "No",
        "start_date": "18-01-2023",
        "time": "12:28 PM",
        "user_name": "Taki Rajani",
        "status": "Ongoing"
      },
      {
        "ref_id": "72",
        "postId": "106764933065187174744",
        "azakhana_name": "hussiani hall ",
        "city_name": "Mahuva ",
        "description": "jsjsisjw",
        "end_date": "31-01-2023",
        "image_path": "Posts_Images\/POST-IMG1564452985.jpg",
        "name_of_schollar": "yes soon",
        "postDateTime": "19-01-2023 12:21 PM",
        "program_list": "Majlis",
        "special_notes": "sjsis8sisjsj",
        "start_date": "17-01-2023",
        "time": "12:20 PM",
        "user_name": "Taki Rajani",
        "status": "Ongoing"
      }
    ],
    "totalPosts": "3",
    "totalPages": 1,
    "perPageLimit": 3,
    "currentPage": 1,
    "hasNextPage": 0
  }''';
  final body = json.decode(jsons);
  return body;
}

相关问题