在列表视图构建器内部更改变量

问题描述 投票:1回答:1

我希望在小部件从Web加载数据时更改变量值,

只想做这样的事情:

_playid = _notes[1].id;
title = _notes[1].title;

但是无论我放在哪里,都会出现错误,

我试图将其设置为列表视图生成器中的设置状态,但是没有运气,因为我不希望通过onPress或on tap方法使用它

有人可以帮忙吗?

flutter flutter-layout flutter-dependencies flutter-test
1个回答
0
投票

我刚刚发现,只是我们必须在initstate的内部获取中使用setstate

  void initState() {
    title = " ";
    fetchNotes().then((value) {
      setState(() {
        _notes.addAll(value);
        _playid = _notes[0].numb;
      });
    });
  }
© www.soinside.com 2019 - 2024. All rights reserved.