gpt4 book ai didi

dart - 具有水平和垂直中心对齐分隔线的 GridView

转载 作者:IT王子 更新时间:2023-10-29 06:46:15 25 4
gpt4 key购买 nike

我正在尝试绘制如下图所示的分隔线。

enter image description here

我正在考虑水平添加 5 列,并使用 1 dp 线使分隔列更小。然而,在 Flutter 中,所有列的宽度都相等,这似乎是我错了。

如何绘制如下图所示的行和列分隔符?

这是我使用的代码

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {

Widget gridSection = Expanded(
flex: 1,
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: 1.0,
shrinkWrap:true,
mainAxisSpacing: 2.0,
crossAxisSpacing: 2.0,
padding: const EdgeInsets.all(4.0),
children: <String>[
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
].map((String url) {
return GridTile(
child: Image.network(url, fit: BoxFit.cover));
}).toList()),
);

Widget body = Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
gridSection,
],
);

return Scaffold(
appBar: AppBar(
title: Text("Example 2 Page"),
),
body: Padding(
padding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 0.0),
child: body,
),
);
}
}

最佳答案

我知道为时已晚,但我认为您可以使用 Stack 实现(或实现),并且线条可以是静态图像,网格位于其上方

关于dart - 具有水平和垂直中心对齐分隔线的 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51194298/

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