Meh*_*mir 2 listview dart flutter
您好,我正在制作一个项目,但我需要自定义列表视图框,如我所包含的图片所示。我尝试了很多选择,但我做不到。
class Butgerlist extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = 'Grid List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: GridView.count(
crossAxisCount: 2,
children: <Widget>[
Container(
child: const Center(
child: (Text("box1")),
),
color: Colors.red,
),
Container(
child: Text("box2"),
color: Colors.yellow,
),
Container(
child: Text("box3"),
color: Colors.orange,
),
Container(
child: Text("box4"),
color: Colors.blue,
),
],
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
我想让我的列表视图像这样。如果您有任何建议,请让我知道。谢谢。
相反,Container
您应该使用Card
并用小部件包装它Padding
。
这应该适合你:
class MyApp extends StatelessWidget {
static const title = 'Title';
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
final border = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
);
final padding = const EdgeInsets.all(4.0);
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: GridView.count(
crossAxisCount: 2,
children: <Widget>[
Padding(
padding: padding,
child: Card(
shape: border,
color: Colors.red,
child: const Center(child: (Text("box1"))),
),
),
Padding(
padding: padding,
child: Card(
shape: border,
child: Text("box2"),
color: Colors.yellow,
),
),
Padding(
padding: padding,
child: Card(
shape: border,
child: Text("box3"),
color: Colors.orange,
),
),
Padding(
padding: padding,
child: Card(
shape: border,
child: Text("box4"),
color: Colors.blue,
),
),
],
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9469 次 |
最近记录: |