android 抖动-键盘隐藏屏幕

f2uvfpb9  于 2023-01-11  发布在  Android
关注(0)|答案(2)|浏览(175)

我正在制作一个聊天应用程序,问题是每当我打开键盘时,我无法滚动到页面的末尾,因此键盘隐藏了页面的一部分

它隐藏了这部分

body: Stack(
      alignment: Alignment.bottomCenter,
      children: [
        GestureDetector(
            onTap: () {
              FocusManager.instance.primaryFocus?.unfocus();
            },
            child: ListView(
              children: [
              Container(
                margin: EdgeInsets.all(10),
                height: MediaQuery.of(context).size.height - 190 ,
                child: ListView(
                  shrinkWrap: true,
                  reverse: true,
                  children: [
                    StreamBuilder(
                        stream: StreamFunction(),
                        builder: (context, snapshot) {
                          return ListView.builder(
                              shrinkWrap: true,
                              controller: _controller,
                              itemCount: messaging!.length,
                              itemBuilder: (context, i) {
                                if (messaging!.isNotEmpty ||
                                    messaging != null) {
                                  if ("${messaging![i]["from"]}" ==
                                      "${snapshot.data}") {
                                    return MyMessage(
                                        "${messaging![i]["message"]}",
                                        "${messaging![i]["timeNow"]}");
                                  } else {
                                    return OtherMessage(
                                        "${messaging![i]["message"]}",
                                        "${messaging![i]["timeNow"]}");
                                  }
                                } else {
                                  return Container();
                                }
                              });
                        }),
                  ],
                ),
              ),
             
            ])),
             Container(
                margin: EdgeInsets.only(right:10, left:10),
                height : 50,
                width: double.infinity,
                color: Colors.white,
                child: Align(
                  alignment: Alignment.topCenter,
                  child: Row(
                    children: <Widget>[
                      GestureDetector(
                        onTap: () {},
                        child: Container(
                          height: 30,
                          width: 30,
                          decoration: BoxDecoration(
                            color: Colors.orange,
                            borderRadius: BorderRadius.circular(30),
                          ),
                          child: Icon(
                            Icons.add,
                            color: Colors.white,
                            size: 20,
                          ),
                        ),
                      ),
                      SizedBox(
                        width: 15,
                      ),
                      Expanded(
                        child: TextField(
                          maxLines: null,
                          controller: msg,
                          decoration: InputDecoration(
                              hintText: "Write message...",
                              hintStyle: TextStyle(color: Colors.black54),
                              border: InputBorder.none),
                        ),
                      ),
                      SizedBox(
                        width: 15,
                      ),
                      FloatingActionButton(
                        mini: true,
                        onPressed: () {
                          if (msg.text.isNotEmpty) {
                            sendMsg(msg.text, '$friendName');
                            msg.clear();
                          }
                        },
                        child: Icon(
                          Icons.send,
                          color: Colors.white,
                          size: 18,
                        ),
                        backgroundColor: Colors.orange,
                        elevation: 0,
                      ),
                    ],
                  ),
                ),
              ),
      ],
    )

所以上面的代码是一个在Stack里面的列表视图,我不能在列表视图里面滚动,我用了shrikwrap,我试着把Stack Package 在一个列里面,但是得到了一个错误

bxgwgixi

bxgwgixi1#

使用支架属性“resizeToAvoidBottomInset”

Scaffold(
    resizeToAvoidBottomInset: true,
    body: "your Widget",
)
c9x0cxw0

c9x0cxw02#

这是因为堆栈隐藏在键盘后面,使用这种树代替:

..展开
...列表视图
发送消息小部件(将显示在底部

相关问题