flutter - 如何在 Flutter 中进行这种 UI 设计
问题描述
我正在制作一个简单的 Flutter 应用程序,它有一堆圆形图标按钮,它们显示在一行中,直到没有更多空间,其余按钮然后显示在下一行中,直到没有更多空间,所以上。
但是我找不到构建小部件的正确方法。(仍然是新的颤振)
这是我正在寻找的结果:(应该支持两种设备方向)
一个真实的例子:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primaryColor: Colors.blue[700]),
home: Scaffold(
appBar: AppBar(
title: Text("App Header"),
centerTitle: true,
),
body: Text("No idea how I should structure the icons/buttons"),
),
);
}
}
标题不是很好,但我不知道如何称呼这个设计。
解决方案
您可以使用Gridview()
请看 -这是一个示例代码
我为你创建一个演示
你也可以复制我的代码
这是我的代码-
import 'package:flutter/material.dart';
class MyHomePage extends StatefulWidget {
MyHomePage({
Key key,
}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Help from Abir"),
),
body: Center(
child: OrientationBuilder(builder: (context, orientation) {
return GridView.count(
padding: EdgeInsets.all(10.0),
crossAxisCount: orientation == Orientation.portrait ? 3 : 5,
children: <Widget>[
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
),
child: IconButton(
iconSize: 60,
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
),
Text("Item")
],
),
],
);
}),
),
);
}
}
推荐阅读
- c++ - 是否将参数加载到空函数的缓存中?
- cobol - + COBOL 中第 7 列中的符号
- javascript - 我可以在反应中使用 fetch 发布文本数据吗
- r - 可过滤的列标题在 R 中的 DT 中未对齐
- javascript - 刷新用循环填充的 DataTables 表
- compiler-errors - 程序不包含适合入口点的静态“Main”方法 ///
- aws-lambda - 如何在无服务器中保护 AWS 访问密钥
- javascript - JavaScript 中的“$$("a")” 是什么意思?
- python - 等待队列填充python多处理的最佳方法
- dialogflow-es - Dialogflow 的后续意图