flutter - 如何在 Flutter 中排列盒子?
问题描述
这是我垂直排列盒子的代码。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
Widget box({width: 100.0, height: 100.0}) => Container(
width: width,
height: height,
color: Colors.grey,
);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
box(),
box(),
box(),
],
),
);
}
}
由于我对 CSS flexbox 有一点经验,将 Column 小部件替换为 Row 以将框排列在行中但它不起作用。只出现了黑屏。我已经确保代码在 MaterialApp 小部件下工作。
出于学习目的,我想让代码尽可能简单。
我需要什么才能使上述代码正常工作?最低要求是什么?或者在这种情况下是否有其他适合 root 的小部件?
感谢您抽出时间阅读我的问题!
解决方案
你需要一个材质应用程序渲染颜色和东西
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Container(
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
box(),
box(),
box(),
],
),
);
);
}
}
推荐阅读
- javascript - 如何通过summernote字段编辑span或div中的文本
- c++ - 基本类型与内置类型 C++ 之间有什么区别
- zapier - 删除zapier中的所有特殊字符
- c# - WPF 中 MediaElement.UnloadedBehavior 的用途是什么?
- mysql - 如何导入返回“索引列大小太大”错误的巨大转储?
- r - 用“:”与“>”或“<”列出事物之间的区别
- c# - 为什么我的 C# 代码没有更新 SQL Server 数据库,尽管我得到了正确的受影响行数
- etl - Informatica 中的微秒问题
- android - 如何使用 Workmanager 将 Android sqlite db 与服务器同步?
- grails - 单页 grails 应用程序,延迟渲染模板