我是 Flutter
的新手,我需要将我的小部件放在一条线上,但它不起作用。请帮助任何人回答。
class HelloWorld extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 50,
width: 50,
color: Colors.red,
Container(
height: 50,
width: 50,
color: Colors.blue,
);
}
}
最佳答案
Container(
height: 50,
width: 50,
color: Colors.red,
Container(
height: 50,
width: 50,
color: Colors.blue,
);
您正在执行的实现方式错误,代码将无法运行,因为您在容器内添加了容器,但它可能会给您带来错误,因为没有为内部容器指定子代作为父代。 你可以只取一行并在其中添加两个容器
Row(
children: <Widget>[
Container(),// you can add the paramenters for both
Container(),
],),
关于flutter - 如何对齐彼此相邻的项目 Flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61951403/