Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SingleChildScrollView height to max height with image background in flutter

In the Login screen, there is a background image and all stuff will be scrollable but SingleChildScrollView is not showing macth_parent height. My aim is to design like 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"
                             ),),
                       ),),],))],),),)),), ));}}

my circle container height is about 200.0 but SingleChildScrollView is not showing full height.

enter image description here

like image 440
Farhana Naaz Ansari Avatar asked Jan 17 '19 13:01

Farhana Naaz Ansari


2 Answers

Code of the required layout - its not 100% but get the job Done. You can Complete it as required.

@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
                    ],
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

OutPut:

enter image description here

like image 167
anmol.majhail Avatar answered Oct 21 '22 13:10

anmol.majhail


A Container widget will size themselves to its child, unless specified. In your case:

...
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')))
...
like image 17
Zroq Avatar answered Oct 21 '22 13:10

Zroq