简体   繁体   English

如何在 Flutter 中使用 2 个不同的 colors 创建布局背景?

[英]How to create layout background with 2 different colors in Flutter?

I am trying to make a layout as seen in the image in Flutter, but I don't get how to create a background with two colors and an overlapping button.我正在尝试按照 Flutter 中的图像进行布局,但我不知道如何使用两个 colors 和一个重叠按钮创建背景。 I don't know if there is a widget able to do this or need some code... Any suggest or help will be great, (this was my very first post ever. sorry if there is something wrong about it!!) Thanks.我不知道是否有一个小部件能够做到这一点或需要一些代码......任何建议或帮助都会很棒,(这是我的第一篇文章。抱歉,如果有什么问题!!)谢谢.

在此处输入图像描述

Do something like this.做这样的事情。

body: Stack(
    children: <Widget>[
      Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Container(
            width: MediaQuery.of(context).size.width,
            height: 300,
            color: Colors.grey,
          ),
        ],
      ),
      Positioned(
        top: 280,
        left: 50,
        right: 50,
        child: RaisedButton(
          color: Colors.white,
          child: Text("Your Button"),
          onPressed: () {},
        ),
      )
    ],
  ),

you will get你会得到

输出布局

Let me know if it works让我知道它是否有效

One possible approach is to use a Stack.一种可能的方法是使用堆栈。 Set the background color to your grey (i think, color blind), add the white piece as an image positioned at the bottom.将背景颜色设置为灰色(我认为是色盲),将白色部分添加为位于底部的图像。 Lastly add your button, again positioned at the bottom.最后添加您的按钮,再次位于底部。

On closer inspection of your image, I now see that what I thought was an image at the bottom was actuall just a color.在仔细检查您的图像后,我现在发现我认为底部的图像实际上只是一种颜色。 All you need are two Container s and a button in a Stack.您只需要两个 Container 和一个 Stack 中的按钮。 The first Container should fill the whole space, the second Container should have a height setting (be responsive here for multiple device sizes) and lastly add your RaisedButton.第一个 Container 应该填满整个空间,第二个 Container 应该有一个高度设置(在此处响应多种设备尺寸),最后添加您的 RaisedButton。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM