【问题标题】:SingleChildScrollView height to max height with image background in flutterSingleChildScrollView 高度到最大高度,图像背景颤动
【发布时间】:2019-06-11 17:02:52
【问题描述】:

在登录屏幕中,有一个背景图像,所有内容都可以滚动,但SingleChildScrollView 没有显示macth_parent 高度。我的目标是设计像here

 class MyLoginOne extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
         body: new Container(
           decoration: new BoxDecoration(
               image: new DecorationImage(
                   fit: BoxFit.cover,
                   image:new NetworkImage('https://i.pinimg.com/originals/c2/47/e9/c247e913a0214313045a8a5c39f8522b.jpg')
               )
           ),
           child: new BackdropFilter(
             filter:new ImageFilter.blur(sigmaX: 1.1,sigmaY:1.1),
             child: new Container(
               decoration: new BoxDecoration(color: Colors.black45.withOpacity(0.5)),
               child: new SingleChildScrollView(
                 child: new Container(
                   child: new Column(
                 children: <Widget>[
                 new Container(
                     height: 200.0,
                     child: new Stack(
                       children: <Widget>[
                         new Align(
                             alignment: AlignmentDirectional.center,
                             child:new Container(
                               height: 120.0,
                               width: 120.0,
                               decoration: new BoxDecoration(
                                   shape: BoxShape.circle,
                                   color: Colors.white30
                               ),
                             )
                         ),
                         new Align(
                           alignment: AlignmentDirectional.center,
                           child: new Container(
                             child: new Text("Farha",style: new TextStyle(
                                 color: Colors.white,
                                 fontSize: 14.0,
                                 fontFamily: "WorkSansLight"
                             ),),
                       ),),],))],),),)),), ));}}

我的圆形容器高度约为 200.0,但 SingleChildScrollView 未显示完整高度。

【问题讨论】:

    标签: android scroll flutter


    【解决方案1】:

    所需布局的代码 - 它不是 100%,但可以完成工作。您可以根据需要填写。

    @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Stack(
            children: <Widget>[
              Container(
                decoration: new BoxDecoration(
                    image: new DecorationImage(
                        fit: BoxFit.cover,
                        image: new NetworkImage(
                            'https://i.pinimg.com/originals/c2/47/e9/c247e913a0214313045a8a5c39f8522b.jpg'))),
              ),
              Center(
                child: SingleChildScrollView(
                  padding: EdgeInsets.all(30.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      CircleAvatar(
                        radius: 58.0,
                        child: Text('Travel'),
                      ),
                      SizedBox(
                        height: 20.0,
                      ),
                      TextFormField(
                        decoration: InputDecoration(
                            prefixIcon: Icon(
                              Icons.person,
                              color: Colors.white,
                            ),
                            hintStyle: TextStyle(color: Colors.white),
                            filled: true,
                            fillColor: Colors.black45,
                            hintText: 'Username'),
                      ),
                      SizedBox(
                        height: 10.0,
                      ),
                      TextFormField(
                        decoration: InputDecoration(
                            filled: true,
                            prefixIcon: Icon(Icons.lock, color: Colors.white),
                            hintStyle: TextStyle(color: Colors.white),
                            fillColor: Colors.black45,
                            hintText: 'Password'),
                      ),
                      SizedBox(
                        height: 15.0,
                      ),
                      FlatButton(
                          onPressed: () {},
                          child: Text(
                            'Forgot your Password?',
                            style: TextStyle(color: Colors.white),
                          )),
                      SizedBox(
                        height: 15.0,
                      ),
                      RaisedButton(
                        onPressed: () {},
                        child: Padding(
                            padding: EdgeInsets.all(15.0),
                            child: Text('LOGIN')),
                        color: Colors.redAccent,
                        textColor: Colors.white,
                      ),
                      SizedBox(
                        height: 10.0,
                      ),
                      RaisedButton(
                        onPressed: () {},
                        child: Padding(
                            padding: EdgeInsets.all(15.0),
                            child: Text('REGISTER')),
                        color: Colors.grey,
                        textColor: Colors.white,
                      ),
                      SizedBox(
                        height: 12.0,
                      ),
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Divider(
                              color: Colors.white,
                              height: 8.0,
                            ),
                          ),
                          SizedBox(
                            width: 8.0,
                          ),
                          Text(
                            'OR',
                            style: TextStyle(color: Colors.white),
                          ),
                          SizedBox(
                            width: 8.0,
                          ),
                          Expanded(
                            child: Divider(
                              color: Colors.white,
                              height: 8.0,
                            ),
                          )
                        ],
                      ),
                      Row(
                        children: <Widget>[
                          // TODO Social Icons
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        );
      }
    

    输出:

    【讨论】:

    • 干得好,我正在做额外的努力来制作这个 UI,但你用更少的小部件做到了。
    • 上下拖拽时,图片中间是不是有“滚动边界”的视觉效果?
    【解决方案2】:

    除非指定,否则Container 小部件将根据其子部件调整自身大小。 在你的情况下:

    ...
    Container(
        height: double.infinity, // <-----
        decoration: new BoxDecoration(
            image: new DecorationImage(
                fit: BoxFit.cover,
                image: new NetworkImage(
                    'https://i.pinimg.com/originals/c2/47/e9/c247e913a0214313045a8a5c39f8522b.jpg')))
    ...
    

    【讨论】:

    • Container(height: double.infinity,) 在水平电话模式下具有单子滚动视图并且容器的容器不适合高度的情况下无法正常工作。还有其他解决方案吗?
    猜你喜欢
    • 2022-01-21
    • 2015-08-13
    • 2021-10-02
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 2019-10-24
    相关资源
    最近更新 更多