-
Notifications
You must be signed in to change notification settings - Fork 0
/
girdview_widget.dart
49 lines (45 loc) · 1.41 KB
/
girdview_widget.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import 'package:flutter/material.dart';
class GridViewWidget extends StatelessWidget {
final List<String> _items = List.generate(30, (index) => 'Item ${index + 1}');
@override
Widget build(BuildContext context) {
var orientation = MediaQuery.of(context).orientation;
return Scaffold(
appBar: AppBar(
title: const Text('GridView Widget'),
),
body: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
mainAxisSpacing: 10,
crossAxisSpacing: 6,
childAspectRatio: 1 / 2,
),
itemCount: _items.length,
itemBuilder: _buildItem,
),
);
}
Widget _buildItem(context, index) => Card(
margin: const EdgeInsets.all(8),
elevation: 8,
child: GridTile(
header: GridTileBar(
backgroundColor: Colors.black26,
title: const Text('header'),
subtitle: Text('Item ${_items[index].split(' ')[1]}'),
),
footer: GridTileBar(
backgroundColor: Colors.black38,
title: const Text('footer'),
subtitle: Text('Item ${_items[index].split(' ')[1]}'),
),
child: Center(
child: Text(
_items[index],
style: const TextStyle(fontSize: 16),
),
),
),
);
}