ListView为默认为空,仅当用户单击搜索栏或热重新加载时,数据才会显示在列表中

时间:2018-05-29 14:27:12

标签: dart flutter

This is what I get in the ListView as soon as I get into this screen, however I am expecting to display all the elements in the List.

As you can see in the second screenshot the elements are only displayed in the ListView only once I click in the Search bar (without typing anything),

我的json回复是:

[
    {
        "id": 791130665,
        "user_id": 513549601,
        "event_id": 843678542,
        "code": "TKHRDSJ",
        "created": "2018-05-25 09:13:15",
        "void": 0
    },
    {
        "id": 937448493,
        "user_id": 513549601,
        "event_id": 843678542,
        "code": "TKUYJGW",
        "created": "2018-05-25 09:14:07",
        "void": 0
    }
]

这是我粘贴Url时获得的Json响应     对于returnTicketDetails的json响应= json.decode(response.body);

1 个答案:

答案 0 :(得分:0)

您的_searchResult作为空列表被初始化,然后您在onSearchTextChanged中更新它。在第一次搜索发生之前,您需要使用其他内容初始化_searchResult

我不确定您的userDetails列表何时可用,但如果它已提前就绪,则初始化_searchResult的好地方将在initState上。

@override
void initState() {
  super.initState();
  onSearchTextChanged('');
}