gpt4 book ai didi

flutter - 用Flutter构建网格布局

转载 作者:行者123 更新时间:2023-12-03 03:32:09 28 4
gpt4 key购买 nike

我在Flutter刚起步,对如何使用小部件为Native Android,RelativeLayout和ConstraintLayout创建可持续替代品感到困惑,但无法正确使用“列,行”小部件。我正在尝试构建此布局,但直到现在仍无法进​​行。
Here is the image
我首先为整个事情添加一个容器,然后为每个“块”添加一列,然后为其余部分使用行/容器。这是我到目前为止编写的代码,但是什么都没有显示:

Container(
height: 250,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: colorItems // a color list at global scope with 2 items
),
color: Colors.black
),
)
],
),
),
)
编辑
请说明您的小部件层次结构,如下所示:
Container
- Column
- Row

最佳答案

我添加了一个完整示例,说明您要尝试获得什么:
以下是小部件树的外观:

WIDGET HEIRARCHY
Container
- Column
- Container
- SizedBox
- Expanded
-Row
- Container
- SizedBox
-Expanded
- Column
- Container
- SizedBox
- Expanded
- Row
- Expanded
- Container
- Expanded
- Container
- Expanded
- Container
class StackOver extends StatelessWidget {
final BoxDecoration _boxDecoration = BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(
15.0,
),
);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Tab bar',
),
),
body: Padding(
padding: const EdgeInsets.all(10.0),
// parent container housing all other widgets
child: Container(
height: 250,
child: Column(
children: [
// frist container [give it a height, it takes up the width of the parent]
Container(
height: 80,
decoration: _boxDecoration,
),

// add spacing
SizedBox(
height: 15,
),

// second child of the column [consists of a Row with children]
Expanded(
child: Row( // row
children: [
Container( // first child
width: 80, // give it a width, it takes up the height of parent since it is wrapped with an expanded widget
decoration: _boxDecoration,
),

// add spacing
SizedBox( // second child
width: 15,
),


Expanded( // thrid child [consists a column with children ]
child: Column(
children: [
Container(
height: 80, // give it a height, it takes up the width of parent since it is wrapped with an expanded widget
decoration: _boxDecoration,
),

// add spacing
SizedBox( // second child
height: 20,
),


Expanded( // third child [consists of a row with 3 containsers]
child: Row(
children: [
Expanded( // first container
child: Container(
decoration: _boxDecoration,
),
),

// add spacing
SizedBox(
width: 15,
),
Expanded( // second container
child: Container(
decoration: _boxDecoration,
),
),

// add spacing
SizedBox(
width: 15,
),
Expanded( // third container
child: Container(
decoration: _boxDecoration,
),
),
],
),
),
],
),
),
],
),
),
],
),
),
),
);
}
}

输出值
enter image description here

关于flutter - 用Flutter构建网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63322624/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com