Flutter Container filling the full screen with rounded edges

Asked

Viewed 3,453 times

1

I would like to know how to make a layout similar to the pictures below in flutter. I tried to use a container, but it did not fill the screen, when I used height: double.infity it disappeared from the screen. ` And if I leave the height fixed on other Vices it won’t be cool.

body: SingleChildScrollView(
        child: Stack(
          children: <Widget>[
            SizedBox(height: 80,),
            Container(
              padding: EdgeInsets.all(10),
              height: 800,
              width: double.infinity,
              color: Colors.transparent,
              child: Container(
                  decoration: new BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(
                        topLeft: const Radius.circular(40.0),
                        topRight: const Radius.circular(40.0),
                      )),
                  child: Column(
                    children: <Widget>[
                      Text("Hu"),
                    ],
                  )),
            )
          ],
        ),
      ),
    );

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

1 answer

1


Either you work with fixed height or make a calculation

MediaQuery.of(context).size.height*0.8

this way your container will occupy 80% of the screen, this on any device.

Change the shape you want...

body: SingleChildScrollView(
        child: Stack(
          children: <Widget>[
            SizedBox(height: 80,),
            Container(
              padding: EdgeInsets.all(10),
              height: MediaQuery.of(context).size.height*0.8,
              width: double.infinity,
              color: Colors.transparent,
              child: Container(
                  decoration: new BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(
                        topLeft: const Radius.circular(40.0),
                        topRight: const Radius.circular(40.0),
                      )),
                  child: Column(
                    children: <Widget>[
                      Text("Hu"),
                    ],
                  )),
            )
          ],
        ),
      ),
    );

Explanation

The class MediaQuery will give you much useful information about your current screen, proportions, measures, context and so on... In your case it is good to use this class because from it you can catch the size thus bringing the measurements of your screen, as the width and the height, so with this you can perform calculations to better display your Widget

If you want to know more about Mediaquery.

  • interesting, I come from the web, this Mediaquery and as if it were the window.screen in javascript?

  • Guy can’t say for sure, I don’t know much about WEB, but from what I’ve seen in some research seems to be the same concept...

  • I understand, I’m going to take the test here of the example you gave me

  • 1

    worked perfectly, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.