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

141 lines
3.8 KiB
Dart
Raw Normal View History

2022-09-13 19:19:52 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2019-02-08 16:20:28 +01:00
import 'package:flutter/cupertino.dart';
2022-09-13 17:52:35 +02:00
import 'package:flutter/material.dart';
2019-11-05 14:22:41 +01:00
import 'package:git_touch/models/theme.dart';
2019-09-04 16:37:22 +02:00
import 'package:git_touch/utils/utils.dart';
2022-09-13 17:52:35 +02:00
import 'package:git_touch/widgets/link.dart';
2019-11-05 14:22:41 +01:00
import 'package:provider/provider.dart';
2019-02-08 16:20:28 +01:00
2019-09-21 17:54:25 +02:00
class TableViewHeader extends StatelessWidget {
2021-05-16 09:16:35 +02:00
final String? title;
2019-09-21 17:54:25 +02:00
2022-09-13 17:52:35 +02:00
const TableViewHeader(this.title, {super.key});
2019-09-21 17:54:25 +02:00
@override
Widget build(BuildContext context) {
2019-12-21 10:26:26 +01:00
final theme = Provider.of<ThemeModel>(context);
2019-09-21 17:54:25 +02:00
return Container(
2022-09-06 18:28:12 +02:00
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
2019-09-21 17:54:25 +02:00
child: Text(
2021-05-16 09:16:35 +02:00
title!.toUpperCase(),
2020-01-27 08:11:51 +01:00
style: TextStyle(color: theme.palette.secondaryText, fontSize: 13),
2019-09-21 17:54:25 +02:00
),
);
}
}
2022-09-13 17:52:35 +02:00
class TableViewItem {
2022-09-13 19:19:52 +02:00
final Widget child;
final IconData? prefixIconData;
final Widget? prefix;
final Widget? extra;
final void Function()? onClick;
2021-05-16 09:16:35 +02:00
final String? url;
2019-09-14 17:48:01 +02:00
final bool hideRightChevron;
2019-02-08 16:20:28 +01:00
2022-09-06 18:28:12 +02:00
const TableViewItem({
2022-09-13 19:19:52 +02:00
required this.child,
this.prefixIconData,
this.prefix,
this.extra,
this.onClick,
2019-09-23 18:34:51 +02:00
this.url,
2019-09-14 17:48:01 +02:00
this.hideRightChevron = false,
2022-09-13 19:19:52 +02:00
}) : assert(prefixIconData == null || prefix == null);
2022-09-13 17:52:35 +02:00
}
class TableViewItemWidget extends StatelessWidget {
const TableViewItemWidget(this.item, {super.key});
final TableViewItem item;
@override
Widget build(BuildContext context) {
final theme = Provider.of<ThemeModel>(context);
return LinkWidget(
2022-09-13 19:19:52 +02:00
onTap: item.onClick,
2022-09-13 17:52:35 +02:00
url: item.url,
child: DefaultTextStyle(
style: TextStyle(fontSize: 17, color: theme.palette.text),
overflow: TextOverflow.ellipsis,
2022-09-06 18:28:12 +02:00
child: SizedBox(
height: 44,
child: Row(
children: [
SizedBox(
2022-09-13 19:19:52 +02:00
width: (item.prefix == null && item.prefixIconData == null)
2022-09-13 17:52:35 +02:00
? 12
: 44,
child: Center(
2022-09-13 19:19:52 +02:00
child: item.prefix ??
Icon(
2022-09-13 19:19:52 +02:00
item.prefixIconData,
color: theme.palette.primary,
size: 20,
)),
),
2022-09-13 19:19:52 +02:00
Expanded(child: item.child),
if (item.extra != null) ...[
DefaultTextStyle(
style: TextStyle(
fontSize: 17,
color: theme.palette.tertiaryText,
),
2022-09-13 19:19:52 +02:00
child: item.extra!,
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 6)
],
2022-09-13 19:19:52 +02:00
if ((item.onClick != null || item.url != null) &&
2022-09-13 17:52:35 +02:00
!item.hideRightChevron)
Icon(Ionicons.chevron_forward,
size: 20, color: theme.palette.tertiaryText)
else
2022-09-06 18:28:12 +02:00
const SizedBox(width: 2),
const SizedBox(width: 8),
],
),
),
),
);
}
2019-02-08 16:20:28 +01:00
}
class TableView extends StatelessWidget {
2022-09-13 19:19:52 +02:00
final Widget? header;
2022-09-13 17:52:35 +02:00
final Iterable<TableViewItem> items;
2019-02-08 16:20:28 +01:00
2022-09-13 17:52:35 +02:00
const TableView({
super.key,
2022-09-13 19:19:52 +02:00
this.header,
2022-09-13 17:52:35 +02:00
required this.items,
});
2019-09-15 09:08:09 +02:00
2019-02-08 16:20:28 +01:00
@override
Widget build(BuildContext context) {
2022-09-13 19:19:52 +02:00
final theme = Provider.of<ThemeModel>(context);
return AntList(
header: header,
items: [
for (final item in items)
AntListItem(
child: item.child,
prefix: item.prefix ??
(item.prefixIconData == null
? null
: Icon(item.prefixIconData)),
extra: item.extra,
onClick: item.onClick != null
? item.onClick!
: item.url != null
? () {
theme.push(context, item.url!);
}
: null,
),
2019-09-04 16:37:22 +02:00
],
2019-02-08 16:20:28 +01:00
);
}
}