小编Roh*_*n D的帖子

Flutter FutureBuilder 未更新

我有一个 Flutter FutureBuilder,需要使用用户提供的新数据进行更新。但是,FutureBuilder 中的 UI 元素不会更新,并且仍然包含旧值。我已经通过打印语句检查了新数据是否已正确加载。问题似乎是 FutureBuilder 在加载新数据时重建小部件。任何帮助表示赞赏。

Future<List<PollItem>> fetchPost(String loc) async {
  return new Future(() async {

    final response = await http
        .post(restip + '/getPosts',
        body: {"data": loc});

    if (response.statusCode == 200) {
      print(response.body);

      // If the call to the server was successful, parse the JSON
      // This function adds json to list
      PollItem.fromJson(json.decode(response.body));

      // list is a list of posts gathered based on the string criteria
      return list;
    } else {
      throw Exception('Failed to load polls');
    }
  }); …
Run Code Online (Sandbox Code Playgroud)

dart flutter

5
推荐指数
1
解决办法
7581
查看次数

Flutter Dismissible 不从树中移除

我正在使用 Flutter 并且正在努力从树中删除一个 Dismissible 对象。下面是我的代码。我创建了一个存储在列表“newlist”中的自定义类。我似乎从 List 和 setState() 中删除了 Dismissible 对象,但它似乎不起作用。任何帮助是极大的赞赏。

   return new Dismissible(key: new Key("newlist"),
direction: DismissDirection.horizontal,
onDismissed: (DismissDirection direction) {
            setState(() {
              newlist.remove(newlist[index]);
              print(newlist.length);

            });
},
child: new ListTile(
leading: const
Icon(Icons.album),
title: new Text(newlist[index].amount),
subtitle: new Text(
newlist[index].name)));
})),
Run Code Online (Sandbox Code Playgroud)

android listview flutter

4
推荐指数
1
解决办法
4058
查看次数

标签 统计

flutter ×2

android ×1

dart ×1

listview ×1