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