1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-08 23:58:46 +01:00

57 lines
1.6 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2019-12-27 15:29:13 +08:00
import 'package:provider/provider.dart';
import '../models/theme.dart';
2019-02-10 12:16:52 +08:00
import '../widgets/empty.dart';
class ListGroup<T> extends StatelessWidget {
final Widget title;
final List<T> items;
2019-02-06 13:06:11 +08:00
final Widget Function(T item, int index) itemBuilder;
2019-03-10 21:26:05 +08:00
final EdgeInsetsGeometry padding;
2019-03-10 21:26:05 +08:00
ListGroup({
2021-05-16 15:16:35 +08:00
required this.title,
required this.items,
required this.itemBuilder,
2019-03-10 21:26:05 +08:00
this.padding = const EdgeInsets.only(left: 10, right: 10, bottom: 10),
});
2019-12-27 15:29:13 +08:00
Widget _buildItem(BuildContext context, MapEntry<int, T> entry) {
final theme = Provider.of<ThemeModel>(context);
return Container(
decoration: BoxDecoration(
2020-01-27 15:11:51 +08:00
border: Border(top: BorderSide(color: theme.palette.border)),
),
2019-02-06 13:06:11 +08:00
child: itemBuilder(entry.value, entry.key),
);
}
@override
Widget build(BuildContext context) {
2019-12-27 15:29:13 +08:00
final theme = Provider.of<ThemeModel>(context);
2019-03-10 21:26:05 +08:00
return Container(
padding: padding,
child: Container(
2019-03-10 21:26:05 +08:00
decoration: BoxDecoration(
2020-01-27 15:11:51 +08:00
border: Border.all(color: theme.palette.border),
2019-03-10 21:26:05 +08:00
borderRadius: BorderRadius.all(Radius.circular(3)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
2019-12-27 15:29:13 +08:00
Container(padding: EdgeInsets.all(8), child: title),
2019-02-10 12:16:52 +08:00
items.isEmpty
? EmptyWidget()
: Column(
2019-12-27 15:29:13 +08:00
children: items
.asMap()
.entries
.map((e) => _buildItem(context, e))
.toList())
],
),
),
);
}
}