git-touch-android-ios-app/lib/widgets/list_group.dart

54 lines
1.6 KiB
Dart
Raw Normal View History

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