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

57 lines
1.6 KiB
Dart
Raw Normal View History

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