颤音:如何定位单个vridview儿童
我有点新手,试图列出所有元素适合屏幕上的列表,并且均匀且对称地放置。我目前正在使用GridView,但我不知道如何更改单个元素的位置。更具体地说,我正在尝试更改最后一行的位置,以使其与其他行对称。
感谢任何帮助或建议!
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Align(
alignment: Alignment.center,
child: Text("Alfabeya Kurdî"),
),
),
body: GridView.count(
crossAxisCount: 8,
childAspectRatio: 3 / 2,
crossAxisSpacing: 50,
mainAxisSpacing: 100,
children: List.generate(
(_alphabet.length - 1),
(index) {
const SizedBox(height: 30);
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Stack(
children: <Widget>[
Positioned.fill(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Color(0xFF0D47A1),
Color(0xFF1976D2),
Color(0xFF42A5F5),
],
),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(16.0),
primary: Colors.white,
textStyle: const TextStyle(fontSize: 20),
),
onPressed: () {},
child: Text(_alphabet[index]),
),
),
],
),
);
},
),
),
);
}
这就是我的GridView当前看起来
I am kind of new to flutter and am trying to make a list where all the elements fit on the screen and are evenly and symmetrically placed. I am currently using GridView, but I can't figure out how to change the position of the individual elements. More specifically, I am trying to change the position of the last row so it's symmetrical with the other rows.
Any help or suggestions are appreciated!
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Align(
alignment: Alignment.center,
child: Text("Alfabeya Kurdî"),
),
),
body: GridView.count(
crossAxisCount: 8,
childAspectRatio: 3 / 2,
crossAxisSpacing: 50,
mainAxisSpacing: 100,
children: List.generate(
(_alphabet.length - 1),
(index) {
const SizedBox(height: 30);
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Stack(
children: <Widget>[
Positioned.fill(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Color(0xFF0D47A1),
Color(0xFF1976D2),
Color(0xFF42A5F5),
],
),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(16.0),
primary: Colors.white,
textStyle: const TextStyle(fontSize: 20),
),
onPressed: () {},
child: Text(_alphabet[index]),
),
),
],
),
);
},
),
),
);
}
This is what my GridView currently looks like
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用带有对齐属性的包装小部件
You can use a wrap widget instead which has alignment property