Flutter 设置子对象的透明颜色以在Flatter中重新创建此布局

Flutter 设置子对象的透明颜色以在Flatter中重新创建此布局,flutter,flutter-layout,Flutter,Flutter Layout,我目前正在学习一门需要重新创建此布局的课程: 我正努力在脚手架中央的第二个盒子上设置透明的黄色。这是我的代码: class myApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(scaffoldBackgroundColor: Colors.teal), home: Scaffo

我目前正在学习一门需要重新创建此布局的课程:

我正努力在脚手架中央的第二个盒子上设置透明的黄色。这是我的代码:

class myApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(scaffoldBackgroundColor: Colors.teal),
      home: Scaffold(
        body: SafeArea(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Container(
                color: Colors.red,
                height: double.infinity,
                width: 100.0,
              ),
              Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Container(
                      color: Colors.yellow,
                      height: 100.0,
                      width: 100.0,
                    ),
                    Container(
                      width: 100.0,
                      height: 100.0,
                      color: Colors.yellowAccent,
                    )
                  ]),
              Container(
                color: Colors.blue,
                height: double.infinity,
                width: 100.0,
              )
            ],
          ),
        ),
      ),
    );
  }
}
类myApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主题:主题数据(脚手架背景颜色:Colors.teal),
家:脚手架(
正文:安全区(
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
容器(
颜色:颜色,红色,
高度:双无限,
宽度:100.0,
),
纵队(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
颜色:颜色,黄色,
高度:100.0,
宽度:100.0,
),
容器(
宽度:100.0,
高度:100.0,
颜色:Colors.yellowAccent,
)
]),
容器(
颜色:颜色,蓝色,
高度:双无限,
宽度:100.0,
)
],
),
),
),
);
}
}

谢谢您的帮助。

只需与
颜色一起使用。黄色。不透明度(0.3)
用于第二个框

类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主题:主题数据(脚手架背景颜色:Colors.teal),
家:脚手架(
正文:安全区(
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
容器(
颜色:颜色,红色,
高度:双无限,
宽度:100.0,
),
纵队(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
颜色:颜色,黄色,
高度:100.0,
宽度:100.0,
),
容器(
宽度:100.0,
高度:100.0,
颜色:颜色。黄色。不透明度(0.3),
)
]),
容器(
颜色:颜色,蓝色,
高度:双无限,
宽度:100.0,
)
],
),
),
),
);
}
}

您可以使用
Colors.fromRGBO
设置黄色的不透明度。例如
Color.fromRGBO(255255,0,您的不透明度值)
。注意不透明度值的范围为0.0到1.0
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(scaffoldBackgroundColor: Colors.teal),
      home: Scaffold(
        body: SafeArea(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Container(
                color: Colors.red,
                height: double.infinity,
                width: 100.0,
              ),
              Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Container(
                      color: Colors.yellow,
                      height: 100.0,
                      width: 100.0,
                    ),
                    Container(
                      width: 100.0,
                      height: 100.0,
                      color: Colors.yellow.withOpacity(0.3),
                    )
                  ]),
              Container(
                color: Colors.blue,
                height: double.infinity,
                width: 100.0,
              )
            ],
          ),
        ),
      ),
    );
  }
}