首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤振- textfield覆盖的listview的最后一个元素

颤振- textfield覆盖的listview的最后一个元素
EN

Stack Overflow用户
提问于 2021-01-13 10:57:10
回答 1查看 129关注 0票数 0

我正在一个颤振应用程序中构建一个注释部分,其中有一个ListView,它在页面底部显示带有容器的所有注释,用户可以在其中键入并添加注释(见下图),为此我使用了StackAlign小部件,现在的问题是最后一个注释(如列表视图中的最后一个元素被输入字段所覆盖)。

我的问题是,解决这个UI错误的可能解决方案是什么?

下面是我正在使用的代码:

代码语言:javascript
复制
class _CommentsListState extends State<CommentsList> {

@override
Widget build(BuildContext context) {
  return Expanded(
    child: Stack(
      children: [
        FutureBuilder<QuerySnapshot>(
            future: commentGrabFtr,
            builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
              if (snapshot.hasData) {
                return ListView.builder(
                  shrinkWrap: true,
                  reverse: false,
                  itemCount: snapshot.data.docs.length,
                  itemBuilder: (BuildContext context, int index) {
                    Comment comment = new Comment.fromMap(snapshot.data.docs[index].data());
                    _docUID = snapshot.data.docs[index].id;
                    return CommentCard(comment: comment,);
                  },
                );
              } else {
                return Center(
                  child: Image.asset('assets/images/nodata.png',),
                );
              }
            }),
        Align(
          alignment: Alignment.bottomCenter,
          child: Container(
            color: Colors.white,
            padding: EdgeInsets.only(left: 10, right: 10, bottom: 12, top: 16),
            child: Material(
              color: Colors.blueGrey[50],
              borderRadius: BorderRadius.all(Radius.circular(8.0)),
              child: TextField(
                controller: _commentInputController,
                decoration: InputDecoration(
                  contentPadding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
                  border: InputBorder.none,
                  hintText: 'start typing...',
                  suffixIcon: IconButton(onPressed: () {}, icon: Icon(FeatherIcons.arrowRightCircle)),
                ),
              ),
            ),
          ),
        )
      ],
    ),
  );
}
}

这是输出:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-13 11:13:23

使用Column而不是Stack

就像这样

代码语言:javascript
复制
@override
Widget build(BuildContext context) {
    return Expanded(
      child: Column(
        children: [
          Expanded(
            child: FutureBuilder<QuerySnapshot>(
                future: commentGrabFtr,
                builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
                  if (snapshot.hasData) {
                    return ListView.builder(
                      shrinkWrap: true,
                      reverse: false,
                      itemCount: snapshot.data.docs.length,
                      itemBuilder: (BuildContext context, int index) {
                        Comment comment = new Comment.fromMap(
                            snapshot.data.docs[index].data());
                        _docUID = snapshot.data.docs[index].id;
                        return CommentCard(
                          comment: comment,
                        );
                      },
                    );
                  } else {
                    return Center(
                      child: Image.asset(
                        'assets/images/nodata.png',
                      ),
                    );
                  }
                }),
          ),
          Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              color: Colors.white,
              padding:
                  EdgeInsets.only(left: 10, right: 10, bottom: 12, top: 16),
              child: Material(
                color: Colors.blueGrey[50],
                borderRadius: BorderRadius.all(Radius.circular(8.0)),
                child: TextField(
                  controller: _commentInputController,
                  decoration: InputDecoration(
                    contentPadding:
                        EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
                    border: InputBorder.none,
                    hintText: 'start typing...',
                    suffixIcon: IconButton(
                        onPressed: () {},
                        icon: Icon(FeatherIcons.arrowRightCircle)),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65700515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档