Flutter 如何在立柱和立柱上进行颤振布局;还吵架吗?
我刚开始学习颤振,我有一个问题,使布局像下图,什么代码使布局 这是我的密码:Flutter 如何在立柱和立柱上进行颤振布局;还吵架吗?,flutter,flutter-layout,Flutter,Flutter Layout,我刚开始学习颤振,我有一个问题,使布局像下图,什么代码使布局 这是我的密码: import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold(
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.teal,
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
height: 100.0,
color: Colors.white,
child: Text('Container 1'),
),
SizedBox(
height: 20.0,
),
Container(
height: 100.0,
color: Colors.blue,
child: Text('Container 2'),
),
SizedBox(
height: 20.0,
),
Container(
height: 100.0,
color: Colors.red,
child: Text('Container 3'),
),
],
),
),
),
);
}
}
导入“包装:颤振/材料.省道”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
背景颜色:Colors.teal,
正文:安全区(
子:列(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
容器(
高度:100.0,
颜色:颜色,白色,
子项:文本(“容器1”),
),
大小盒子(
身高:20.0,
),
容器(
高度:100.0,
颜色:颜色,蓝色,
子项:文本('Container 2'),
),
大小盒子(
身高:20.0,
),
容器(
高度:100.0,
颜色:颜色,红色,
子项:文本(“容器3”),
),
],
),
),
),
);
}
}
从我写的代码,完全不同于我所期望的,请帮助,我在这方面是新的,我想让我的技能更先进一步。谢谢你…给你
Scaffold(
backgroundColor: Colors.teal,
body: Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
color: Colors.red,
height: 100.0,
width: 100.0,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.yellow,
height: 100.0,
width: 100.0,
)
],
),
),
Container(
color: Colors.blue,
height: 100.0,
width: 100.0,
),
],
),
),
),
脚手架(
背景颜色:Colors.teal,
主体:容器(
孩子:排(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
容器(
颜色:颜色,红色,
高度:100.0,
宽度:100.0,
),
扩大(
子:列(
crossAxisAlignment:crossAxisAlignment.center,
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
颜色:颜色,黄色,
高度:100.0,
宽度:100.0,
)
],
),
),
容器(
颜色:颜色,蓝色,
高度:100.0,
宽度:100.0,
),
],
),
),
),
我只是将您的列
小部件转换为行
,并在其中添加一个中心小部件,其中包含展开
并在那里添加列
小部件
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
color: Colors.red,
height: 100.0,
width: 100.0,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.yellow,
height: 100.0,
width: 100.0,
),
Container(
color: Colors.green,
height: 100.0,
width: 100.0,
)
],
),
),
Container(
color: Colors.blue,
height: 100.0,
width: 100.0,
),
],
),
子项:行(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
容器(
颜色:颜色,红色,
高度:100.0,
宽度:100.0,
),
扩大(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
颜色:颜色,黄色,
高度:100.0,
宽度:100.0,
),
容器(
颜色:颜色。绿色,
高度:100.0,
宽度:100.0,
)
],
),
),
容器(
颜色:颜色,蓝色,
高度:100.0,
宽度:100.0,
),
],
),
这一个有效!谢谢你的帮助,我才意识到我可以使用扩展的东西:)