代码之家  ›  专栏  ›  技术社区  ›  Farhana Naaz Ansari Jay Dwivedi

颤振:键盘出现时背景图像被挤压

  •  1
  • Farhana Naaz Ansari Jay Dwivedi  · 技术社区  · 6 年前

    当键盘出现时,背景图像被挤压。

    Scaffold(
            body: Stack(
              children: <Widget>[
    
                Container(
                  width:double.infinity ,
                  height: double.infinity ,
                  child: Image.asset('assets/images/bg.png')),
                Container(
                    child: SingleChildScrollView(
                      padding: EdgeInsets.all(width*0.10),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: <Widget>[
                          SizedBox(height: height*0.10,),
                          Container(decoration: BoxDecoration(color:Colors.transparent),child: Container(margin: EdgeInsets.only(bottom: height*0.02,left: 20.0,right: 20.0),child: Image.asset('assets/images/logo.png'),),),
                          SizedBox(height: height*0.05,),
                          Container(
                              decoration: BoxDecoration(color: Colors.transparent),
                              child: new Form(
                                  key: _formKey,
                                  autovalidate: _autoValidate,
                                  child: LoginFrom(width,height))),
    
                        ],
                      ),
                    ),
                  ),
    
    
              ],
            )
    
        )
    

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  0
  •   Farhana Naaz Ansari Jay Dwivedi    6 年前

    看起来您只需要移动背景图像就可以成为父窗口小部件。即

    return new Scaffold(
            appBar: new AppBar(
              title: new Text(widget.title),
            ),
            body: Container(
                width: double.infinity,
                height: double.infinity,
                decoration: BoxDecoration(
                  image: DecorationImage(
                      image: ExactAssetImage('assets/images/bg.png'),
                      fit: BoxFit.fill,
                      alignment:Alignment.topCenter,
                      ),     
                ),
                child: Stack(
                  children: <Widget>[
                    Container(
                      child: SingleChildScrollView(
                        padding: EdgeInsets.all(width * 0.10),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.stretch,
                          children: <Widget>[
                            SizedBox(
                              height: height * 0.10,
                            ),
                            Container(
                              decoration: BoxDecoration(color: Colors.transparent),
                              child: Container(
                                margin: EdgeInsets.only(
                                    bottom: height * 0.02, left: 20.0, right: 20.0),
                                child: Image.asset('assets/images/logo.png'),
                              ),
                            ),
                            SizedBox(
                              height: height * 0.05,
                            ),
                            Container(
                                decoration:
                                    BoxDecoration(color: Colors.transparent),
                                child: Container()
                                new Form(
                                    key: _formKey,
                                    autovalidate: _autoValidate,
                                    child: LoginFrom(width, height))
                                    ),
                          ],
                        ),
                      ),
                    ),
                  ],
                )) // This trailing comma makes auto-formatting nicer for build methods.
            );