SingleChildScrollView不滚动

时间:2020-06-28 15:19:33

标签: flutter flutter-layout

当键盘出现但我没有滚动时,我试图滚动表单。隐藏键盘时,没有溢出,只需要在键盘出现时滚动即可。

Widget build(BuildContext context) {
return Scaffold(
  resizeToAvoidBottomInset: false,
  body: Stack(
    children: <Widget>[
      Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(...),
            SingleChildScrollView(
              child: Padding(
                padding: EdgeInsets.symmetric(
                    horizontal: ScreenUtil().setWidth(40)),
                child: Column(crossAxisAlignment: CrossAxisAlignment.start,

                  children: <Widget>[
                    Container(
                      alignment: Alignment.center,
                      child: Image(
                        image: AssetImage("assets/images/logoBrown.png"),
                        alignment: Alignment.center,
                        fit: BoxFit.cover,
                        height: ScreenUtil().setHeight(146),
                        width: ScreenUtil().setWidth(195),
                      ),
                    ),
                    Form(
                      child: Column(
                        children: <Widget>[...],
                      ),
                    )
                  ],
                ),
              ),
            )
          ],
        ),
      )
    ],
  ),
);

}

2 个答案:

答案 0 :(得分:0)

已解决。解决这个问题,但我想这与层次结构有关。当保持简单时,它起作用了。这是新代码。感谢您的帮助。

    @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: true,
      body: Stack(
        overflow: Overflow.visible,
        children: <Widget>[
          SingleChildScrollView(
            child: Padding(
              padding: EdgeInsets.only(top: ScreenUtil().setHeight(180)),
              child: Padding(
                padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(40) ,),
                child: Container(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[...],

                  ),
                ),
              ),
            ),
          ),
          Container(...),
          Align(
            alignment: Alignment.bottomCenter,
            child: Container(...)
        ],
      ),
    );
  }

答案 1 :(得分:0)

在脚手架中设置 resizeToAvoidBottomInset:true

  Widget build(BuildContext context) {
   return Scaffold(
   resizeToAvoidBottomInset: true,
   body: Stack(
     _ _ _ _
     _ _ _ _
     _ _ _ _
     _ _ _ _
    )