Flutter Layout Container Margin

白昼怎懂夜的黑 提交于 2020-07-17 07:09:24

问题


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


回答1:


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



回答2:


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()
)


来源:https://stackoverflow.com/questions/49369950/flutter-layout-container-margin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!