Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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
Flutter 如何在Flatter中聚焦listView的最后一项_Flutter - Fatal编程技术网

Flutter 如何在Flatter中聚焦listView的最后一项

Flutter 如何在Flatter中聚焦listView的最后一项,flutter,Flutter,我试图让我的listview始终关注聊天中的最后一个元素,但我不知道如何做到这一点,如果有人能帮助我,我将不胜感激 Widget ChatMessageList(){ return StreamBuilder( stream: chatMessageStream, builder: (context, snapshot){ return snapshot.hasData ? ListView.builder( controlle

我试图让我的listview始终关注聊天中的最后一个元素,但我不知道如何做到这一点,如果有人能帮助我,我将不胜感激

Widget ChatMessageList(){
    return StreamBuilder(
      stream: chatMessageStream,
      builder: (context, snapshot){
        return snapshot.hasData ? ListView.builder(
          controller: _scrollController,
          itemCount: snapshot.data.documents.length,
          itemBuilder: (context, index){
            return MessageTile(snapshot.data.documents[index].data()['message'],
                snapshot.data.documents[index].data()['sendBy'] == userSnapshop.uid);
          }
        ) : Container();
      },
    );
  }

列表视图可以通过包装另一个可滚动的小部件来反转

因此,您只需要通过SingleChildScrollView包装ListView,并通过Reverse属性更改读取方向

SingleChildScrollView(
        reverse: true,
        child: ListView.builder(
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          itemCount: 100,
          itemBuilder: (context, index) => Text(
            index.toString(),
          ),
        ),
      )

对不起,在更新消息的状态下,我应该将此函数附加到哪里?
SingleChildScrollView(
        reverse: true,
        child: ListView.builder(
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          itemCount: 100,
          itemBuilder: (context, index) => Text(
            index.toString(),
          ),
        ),
      )