Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Layout Container Margin

I have a problem with my Flutter Layout.

I have a simple container with a Margin right and left of 20.0 Inside this container i have another container.

But this container does not fit to the parent container only on the left side. I dont know why this happens.

Here is my Code:

  @override   Widget build(BuildContext context) {     return new Scaffold(       backgroundColor: Colors.white,       body: new Container(         margin: new EdgeInsets.symmetric(horizontal: 20.0),         child: new Container(          )       ),     );   } 

Screenshot of the Problem

like image 840
M. Berg Avatar asked Mar 19 '18 18:03

M. Berg


People also ask

How do you set the margins on a container in Flutter?

To set Margin for Container widget in Flutter, set margin property wit the required EdgeInsets value. We can set margin for top, right, bottom, and left with separate values using EdgeInsets. fromLTRB(), or a set a same value for margin on all sides.

What is margin property of a container in Flutter?

Margin property is used to set empty space around an object or Widget in Flutter. Most of the flutter widgets directly do not support margin property but using the Child Wrapping technique we can apply a margin to any widget in flutter using Container widget.

How do you set the position of a container in Flutter?

Here's how you do it:Step 1: Wrap the Stack's child widget inside the Position widget. Step 2: Inside the Position widget, add the top , right , bottom , left property and give it a value. For example, setting top:15 and right:0 will position a widget on the top right of your screen with 15 px space from the top.


2 Answers

You can use left and right values :)

@override Widget build(BuildContext context) {   return Scaffold(     backgroundColor: Colors.white,     body: Container(       margin: const EdgeInsets.only(left: 20.0, right: 20.0),       child: Container(),     ),   ); } 
like image 85
Adonis González Avatar answered Sep 22 '22 13:09

Adonis González


You can try: To the margin of any one edge

new Container(     margin: const EdgeInsets.only(left: 20.0, right: 20.0),     child: new Container() ) 

You can try :To the margin of any all edge

new Container(     margin: const EdgeInsets.all(20.0),     child: new Container() ) 

If you need the current system padding or view insets in the context of a widget, consider using [MediaQuery.of] to obtain these values rather than using the value from [dart:ui.window], so that you get notified of changes.

new Container(     margin: EdgeInsets.fromWindowPadding(padding, devicePixelRatio),     child: new Container() ) 
like image 25
vinod yadav Avatar answered Sep 24 '22 13:09

vinod yadav