16

I am new in Flutter so I want to know that how can I set a width to match parent layout width

new Scaffold(
    body: new Container(
  decoration: new BoxDecoration(color: AppColors.hoBlue),
  child: Padding(
    padding: EdgeInsets.all(20.0),
    child: new Center(
        child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Stack(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                  child: Padding(
                    padding: EdgeInsets.all(20.0),
                    child: Card(
                      child: Padding(
                          padding: EdgeInsets.fromLTRB(20, 0.0, 20.0,20.0),
                          child: Column(
                            children: <Widget>[
                               Card(
                                    elevation: 10.0,
                                    child: Padding(
                                      padding: EdgeInsets.all(20.0),
                                      child:
                                      Text("Sign Up Here"),
                                    ),
                                  ),
                              TextField(
                                decoration: InputDecoration(
                                  labelText: "Email",
                                  hintText: "example@mail.com",
                                ),
                                autofocus: true,
                              ),
                              TextField(
                                decoration: InputDecoration(
                                  labelText: "Password",
                                ),
                                autofocus: true,
                              ),
                              SizedBox(
                                width: double.infinity,
                                // height: double.infinity,
                                child: new RaisedButton(
                                  color: AppColors.hoBlue,
                                  child: Text(
                                    "Sign In",
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontFamily: 'Raleway',
                                      fontSize: 22.0,
                                    ),
                                  ),
                                  onPressed: () => print('Sign In'),
                                ),
                              )
                            ],
                          )),
                    ),
                  ),
                ),
              ],
            )
          ],
        ),
      ],
    )),
  ),
));

Result From Code Above

i need help to make card stack with parent like Result I want

i already try with using stack but the result card parent card overlaping the first card.

I know about little bit on Expanded tag but Expanded expand view to both direction, i dont know how to do it. Help me if you know, Thanks in Advance.

Iqbal M
  • 165
  • 1
  • 1
  • 9

4 Answers4

31

You don't need Stack to get that view - it can be done using Column & Material widget.

return Scaffold(
        body: new Container(
      decoration: new BoxDecoration(color: Colors.blue),
      child: new Center(
          child: MergeSemantics(
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
              Card(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    Material(
                      elevation: 24.0,
                      child: Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: Text("Sign Up Here"),
                      ),
                    ),
                    Padding(
                        padding: EdgeInsets.fromLTRB(20, 10.0, 20.0, 20.0),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.stretch,
                          children: <Widget>[
                            TextField(
                              decoration: InputDecoration(
                                labelText: "Email",
                                hintText: "example@mail.com",
                              ),
                              autofocus: true,
                            ),
                            TextField(
                              decoration: InputDecoration(
                                labelText: "Password",
                              ),
                              autofocus: true,
                            ),
                            SizedBox(
                              width: double.infinity,
                              // height: double.infinity,
                              child: new RaisedButton(
                                color: Colors.blue,
                                child: Text(
                                  "Sign In",
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontFamily: 'Raleway',
                                    fontSize: 22.0,
                                  ),
                                ),
                                onPressed: () => print('Sign In'),
                              ),
                            )
                          ],
                        )),
                  ],
                ),
              ),
        ],
      ),
            ),
          )),
    ));

Output: enter image description here

anmol.majhail
  • 48,256
  • 14
  • 136
  • 105
9

If you want to resize or alter the card view Then just put Card inside the Container view then adjust your container size. This link will help you :https://stackoverflow.com/a/50017126/7418129

user7418129
  • 1,074
  • 14
  • 18
8

Just Put Card in Container

Padding(
            padding: EdgeInsets.all(20),
            child: Container(
              height: 50,
              width: double.infinity,
              child: Card(
                child: Align(
                    alignment: Alignment.centerLeft,
                    child: Text("Edit Profile")),
              ),
            ),
          )
Shailendra Rajput
  • 2,131
  • 17
  • 26
  • 2
    In my case, using the DevTools I found out that the Card has a margin of 1 by default, u can use the Card inside the Container, but if u want the Card to completely fill the Container set the Card's margin to: margin: EdgeInsets.zero. – Ramiro G.M. May 04 '22 at 21:05
  • It's better to use a SizedBox instead of a container. – Praveen Thirumurugan May 07 '22 at 07:35
0

Use Material widget that will use as same as card do...and take always a full width and height as same as its parent class...

Ankush Mishra
  • 191
  • 2
  • 6