【问题标题】:Flutter Remove Duplicated ListViewFlutter 删除重复的 ListView
【发布时间】:2021-11-12 01:23:47
【问题描述】:

在我的应用程序中,我收到如下 API 响应

{
    "success": true,
    "data": {
        "items": [
            {
                "sequenceno": 1933,
                "_id": "5eff1",
                "chapter": "Numbers and Numeration",
                "title": "Place Value: 3-digits",
                "package_description": "This learning module helps to familiarise with the concept of place value of 3-digit numbers.",
                "age_level": [
                    99,
                    8
                ],
                "pkg_sequence": "2501",
                "packagescors": {
                    "score": [
                        50
                    ],
                    "date": [
                        "1600259121340"
                    ]
                }
            },
            {
                "sequenceno": 1933,
                "_id": "5d79",
                "chapter": "Numbers and Numeration",
                "title": "Place Value: 4-digits",
                "package_description": "This learning module helps the kids familiarise with the concept of Place value of a number.",
                "age_level": [
                    99,
                    8
                ],
                "pkg_sequence": "2501",
                "packagescors": {
                    "score": [
                        60
                    ],
                    "date": [
                        "1615283866457"
                    ]
                }
            },
            ]

数据是来自具有章节和章节标题的主题的模块。每个数据都有一个名为“章节”的键。每当构建列表视图时,数据都会重复

如何删除重复项并正确构建列表?

【问题讨论】:

    标签: flutter flutter-listview


    【解决方案1】:

    试试这个。

    final ids = myList.map((e) => e.id).toSet();
        myList.retainWhere((x) => ids.remove(x.id)); // set your response param instead of id.
    

    【讨论】: