2019-02-08 16:20:28 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-09-04 16:37:22 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:primer/primer.dart';
|
2019-02-08 16:20:28 +01:00
|
|
|
import 'link.dart';
|
|
|
|
|
2019-09-04 16:37:22 +02:00
|
|
|
class TableViewSeperator extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
height: 20,
|
|
|
|
color: PrimerColors.gray100,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 16:20:28 +01:00
|
|
|
class TableViewItem {
|
2019-09-04 16:59:33 +02:00
|
|
|
final Widget text;
|
|
|
|
final Widget leftWidget;
|
|
|
|
final Widget rightWidget;
|
2019-02-08 16:20:28 +01:00
|
|
|
final void Function() onTap;
|
|
|
|
final WidgetBuilder screenBuilder;
|
|
|
|
|
|
|
|
TableViewItem({
|
|
|
|
this.text,
|
2019-09-04 16:59:33 +02:00
|
|
|
this.leftWidget,
|
|
|
|
this.rightWidget,
|
2019-02-08 16:20:28 +01:00
|
|
|
this.onTap,
|
|
|
|
this.screenBuilder,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class TableView extends StatelessWidget {
|
2019-09-04 16:37:22 +02:00
|
|
|
final String headerText;
|
2019-02-08 16:20:28 +01:00
|
|
|
final List<TableViewItem> items;
|
|
|
|
|
2019-09-04 16:37:22 +02:00
|
|
|
TableView({this.headerText, @required this.items});
|
|
|
|
|
2019-09-05 11:58:14 +02:00
|
|
|
static final _border = BorderView();
|
|
|
|
static final _seperator = BorderView();
|
2019-09-04 16:37:22 +02:00
|
|
|
|
2019-09-05 11:58:14 +02:00
|
|
|
Widget _buildItem(TableViewItem item) {
|
|
|
|
var widget = Container(
|
|
|
|
height: 44,
|
|
|
|
child: Row(children: [
|
2019-09-12 10:30:35 +02:00
|
|
|
if (item.leftWidget != null) ...[
|
|
|
|
SizedBox(width: 12),
|
|
|
|
item.leftWidget,
|
|
|
|
],
|
2019-09-05 11:58:14 +02:00
|
|
|
SizedBox(width: 12),
|
|
|
|
Expanded(
|
|
|
|
child: DefaultTextStyle(
|
|
|
|
child: item.text,
|
2019-09-08 16:17:29 +02:00
|
|
|
style: TextStyle(fontSize: 16, color: PrimerColors.gray900),
|
2019-09-05 11:58:14 +02:00
|
|
|
),
|
|
|
|
),
|
2019-09-12 10:30:35 +02:00
|
|
|
if (item.rightWidget != null) item.rightWidget,
|
2019-09-05 11:58:14 +02:00
|
|
|
SizedBox(width: 12),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (item.onTap == null && item.screenBuilder == null) {
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
return Link(
|
|
|
|
onTap: item.onTap,
|
|
|
|
screenBuilder: item.screenBuilder,
|
|
|
|
child: widget,
|
|
|
|
);
|
|
|
|
}
|
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-12 10:30:35 +02:00
|
|
|
if (headerText != null)
|
|
|
|
Container(
|
|
|
|
color: PrimerColors.gray100,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
|
|
child: Text(
|
|
|
|
headerText,
|
|
|
|
style: TextStyle(color: PrimerColors.gray600, fontSize: 13),
|
|
|
|
),
|
|
|
|
),
|
2019-09-04 16:37:22 +02:00
|
|
|
_border,
|
2019-09-05 11:58:14 +02:00
|
|
|
...join(_seperator, items.map(_buildItem).toList()),
|
2019-09-04 16:37:22 +02:00
|
|
|
_border,
|
|
|
|
],
|
2019-02-08 16:20:28 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|