Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ListView中的小部件在滚动时处于丢失状态_Listview_Widget_Flutter - Fatal编程技术网

ListView中的小部件在滚动时处于丢失状态

ListView中的小部件在滚动时处于丢失状态,listview,widget,flutter,Listview,Widget,Flutter,我正在从web(世界杯比赛)获取一个JSON,并用它构建一个列表视图 Widget build(BuildContext context) { return new Material( child: _isLoading ? new Center(child: new CircularProgressIndicator()) : new ListView.builder( itemCount: matches != null ? matches["

我正在从web(世界杯比赛)获取一个JSON,并用它构建一个列表视图

Widget build(BuildContext context) {
return new Material(
  child: _isLoading
      ? new Center(child: new CircularProgressIndicator())
      : new ListView.builder(
          itemCount: matches != null ? matches["jogos"].length : 0,
          itemBuilder: (BuildContext context, int index) {
            GameBetCard actualGameBetCard = new GameBet(
              homeTeamName: matches["jogos"][index]["m_clube"],
              awayTeamName: matches["jogos"][index]["v_clube"],
              homeTeamId: matches["jogos"][index]["id_clubem"],
              awayTeamId: matches["jogos"][index]["id_clubev"],
              date: matches["jogos"][index]["data"] +
                  " - " +
                  matches["jogos"][index]["hora"],
              stage: Stage.groups,
              groupName: matches["jogos"][index]["nome_grupo"],
              scoreHomeBet: "",
              scoreAwayBet: "",
              scoreHome: matches["jogos"][index]["placarm_tn"],
              scoreAway: matches["jogos"][index]["placarv_tn"],
            ).gameBetCard;
            _addGameBetToList(actualGameBetCard);
            return actualGameBetCard;
          },
        ),
);}
我在Gamebecard中有2个TextFormFields,当我在其中插入内容时,向下滚动并再次向上滚动,该卡将在TextFormField中没有我的数据的情况下再次启动。还有一件事,我有一个按钮,当点击它时,它会插入firebase数据库,然后它完成了,我更改了检查图标的图标,但在TextFormField的相同情况下,它会在超出“屏幕范围”时重新启动

ps:我在调试时看到ListView只渲染屏幕上显示的iTen。当它出来时,它就被处理掉了。当它返回时,默认情况下会再次启动

我该怎么处理呢?我希望它保存我的小部件的状态


您的TextFormField需要有自己的TextEditingController

这些TextEditingController应该位于顶部小部件(包含ListView的小部件)。如果不这样做,当单个小部件被销毁/重新创建时,TextEditingController也将被销毁/重新创建

在顶部创建两个TextEditingController并将其传递给GameBet小部件,然后将其设置为内部的TextFormFields

另外,顶部的小部件应该是有状态的小部件,这样在重建小部件时控制器就不会被破坏。最后,还应处置控制器

请参见此示例:

类MyForm扩展StatefulWidget{
@凌驾
_MyFormState createState()=>\u MyFormState();
}
类_MyFormState扩展了状态{
text编辑控制器_controller1、_controller2;
@凌驾
void initState(){
super.initState();
_controller1=新文本编辑控制器();
_controller2=新文本编辑控制器();
}
@凌驾
无效处置(){
super.dispose();
_控制器1.dispose();
_控制器2.dispose();
}
@凌驾
小部件构建(构建上下文){
退回新材料(
子项:ListView.builder(
itemCount:count,
itemBuilder:(构建上下文,int索引){
回程赌注(
控制器1:_控制器1,
控制器2:_控制器2,
//其他领域
);
},
),
);
}
}
然后,在游戏赌注中,记住设置控制器:

TextFormField(
控制器:_控制器1,
)

给你的
列表视图
一个
PageStorageKey
Hmmmm我会搜索的!