[英]How do I make this UI design in Flutter
我正在制作一个简单的 Flutter 应用程序,它有一堆圆形图标按钮,这些按钮显示在一行中直到没有更多空间,然后按钮的 rest 显示在下一行直到没有更多空间等等在。
但是我找不到构建小部件的正确方法。 (仍然是颤振的新手)
这是我正在寻找的结果:(应该支持两种设备方向)
一个真实的例子:
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")
],
),
],
);
}),
),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.