1
0
mirror of https://github.com/git-touch/git-touch synced 2025-03-10 16:20:04 +01:00

121 lines
3.6 KiB
Dart
Raw Normal View History

2019-02-08 23:20:28 +08:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
2019-11-05 21:22:41 +08:00
import 'package:git_touch/models/theme.dart';
2019-09-04 22:37:22 +08:00
import 'package:git_touch/utils/utils.dart';
2019-10-02 14:58:11 +08:00
import 'package:git_touch/widgets/border_view.dart';
2019-11-05 21:22:41 +08:00
import 'package:provider/provider.dart';
2019-02-08 23:20:28 +08:00
import 'link.dart';
2019-09-21 23:54:25 +08:00
class TableViewHeader extends StatelessWidget {
2021-05-16 15:16:35 +08:00
final String? title;
2019-09-21 23:54:25 +08:00
TableViewHeader(this.title);
@override
Widget build(BuildContext context) {
2019-12-21 17:26:26 +08:00
final theme = Provider.of<ThemeModel>(context);
2019-09-21 23:54:25 +08:00
return Container(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
child: Text(
2021-05-16 15:16:35 +08:00
title!.toUpperCase(),
2020-01-27 15:11:51 +08:00
style: TextStyle(color: theme.palette.secondaryText, fontSize: 13),
2019-09-21 23:54:25 +08:00
),
);
}
}
2019-02-08 23:20:28 +08:00
class TableViewItem {
2019-09-04 22:59:33 +08:00
final Widget text;
2021-05-16 15:16:35 +08:00
final IconData? leftIconData;
final Widget? leftWidget;
final Widget? rightWidget;
final void Function()? onTap;
final String? url;
2019-09-14 23:48:01 +08:00
final bool hideRightChevron;
2019-02-08 23:20:28 +08:00
TableViewItem({
2021-05-16 15:16:35 +08:00
required this.text,
2019-09-14 23:48:01 +08:00
this.leftIconData,
2019-09-04 22:59:33 +08:00
this.leftWidget,
this.rightWidget,
2019-02-08 23:20:28 +08:00
this.onTap,
2019-09-24 00:34:51 +08:00
this.url,
2019-09-14 23:48:01 +08:00
this.hideRightChevron = false,
}) : assert(leftIconData == null || leftWidget == null);
2019-02-08 23:20:28 +08:00
}
class TableView extends StatelessWidget {
2021-05-16 15:16:35 +08:00
final String? headerText;
2019-09-15 00:01:15 +08:00
final Iterable<TableViewItem> items;
2019-09-15 15:08:09 +08:00
final bool hasIcon;
2019-02-08 23:20:28 +08:00
2019-09-15 15:08:09 +08:00
double get _leftPadding => hasIcon ? 44 : 12;
2021-05-16 15:16:35 +08:00
TableView({this.headerText, required this.items, this.hasIcon = false});
2019-09-04 22:37:22 +08:00
2019-02-08 23:20:28 +08:00
@override
Widget build(BuildContext context) {
2019-12-21 17:26:26 +08:00
final theme = Provider.of<ThemeModel>(context);
2019-11-05 21:22:41 +08:00
2019-09-04 22:37:22 +08:00
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
2019-09-21 23:54:25 +08:00
if (headerText != null) TableViewHeader(headerText),
2019-10-02 16:09:54 +08:00
CommonStyle.border,
2019-11-05 21:22:41 +08:00
...join(
2020-01-04 22:46:59 +08:00
BorderView(leftPadding: _leftPadding),
items.map((item) {
var leftWidget = item.leftWidget;
if (leftWidget == null && hasIcon) {
leftWidget = Icon(
item.leftIconData,
2020-01-27 15:11:51 +08:00
color: theme.palette.primary,
2020-01-04 22:46:59 +08:00
size: 20,
);
}
2019-11-05 21:22:41 +08:00
2021-05-16 15:16:35 +08:00
return LinkWidget(
2020-01-04 22:46:59 +08:00
onTap: item.onTap,
url: item.url,
child: DefaultTextStyle(
2020-01-27 15:11:51 +08:00
style: TextStyle(fontSize: 17, color: theme.palette.text),
2019-11-05 21:22:41 +08:00
overflow: TextOverflow.ellipsis,
child: Container(
height: 44,
child: Row(
children: [
2019-12-21 16:16:17 +08:00
SizedBox(
width: _leftPadding,
child: Center(child: leftWidget),
),
2019-11-05 21:22:41 +08:00
Expanded(child: item.text),
if (item.rightWidget != null) ...[
DefaultTextStyle(
style: TextStyle(
2020-01-27 10:47:34 +08:00
fontSize: 17,
2020-01-27 15:11:51 +08:00
color: theme.palette.tertiaryText,
2019-11-05 21:22:41 +08:00
),
2021-05-16 15:16:35 +08:00
child: item.rightWidget!,
2019-11-05 21:22:41 +08:00
),
SizedBox(width: 6)
],
2019-12-12 20:29:56 +08:00
if ((item.onTap != null || item.url != null) &&
2019-11-05 21:22:41 +08:00
!item.hideRightChevron)
2021-02-14 22:17:22 +08:00
Icon(Ionicons.chevron_forward,
2020-01-27 15:11:51 +08:00
size: 20, color: theme.palette.tertiaryText)
2019-11-05 21:22:41 +08:00
else
SizedBox(width: 2),
SizedBox(width: 8),
],
),
),
2020-01-04 22:46:59 +08:00
),
);
}).toList(),
),
2019-10-02 16:09:54 +08:00
CommonStyle.border,
2019-09-04 22:37:22 +08:00
],
2019-02-08 23:20:28 +08:00
);
}
}