1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-22 14:27:46 +01:00

refactor: files list with table view

This commit is contained in:
Rongjian Zhang 2019-09-15 00:01:15 +08:00
parent 124ec611ad
commit c14fdb4a1d
3 changed files with 53 additions and 80 deletions

View File

@ -2,6 +2,7 @@ import 'package:flutter_highlight/themes/github.dart';
import 'package:git_touch/screens/image_view.dart'; import 'package:git_touch/screens/image_view.dart';
import 'package:git_touch/widgets/app_bar_title.dart'; import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/markdown_view.dart'; import 'package:git_touch/widgets/markdown_view.dart';
import 'package:git_touch/widgets/table_view.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_highlight/flutter_highlight.dart'; import 'package:flutter_highlight/flutter_highlight.dart';
@ -42,29 +43,21 @@ class ObjectScreen extends StatelessWidget {
static const _iconDefaultColor = PrimerColors.blue300; static const _iconDefaultColor = PrimerColors.blue300;
List<Widget> _buildIcon(item) { Widget _buildIcon(item) {
switch (item['type']) { switch (item['type']) {
case 'blob': case 'blob':
return [ return SetiIcon(item['name'], size: 36);
SizedBox(width: 6),
SetiIcon(item['name'], size: 28),
SizedBox(width: 6),
];
case 'tree': case 'tree':
case 'commit': case 'commit':
return [ return Icon(
SizedBox(width: 10),
Icon(
item['type'] == 'tree' item['type'] == 'tree'
? Octicons.file_directory ? Octicons.file_directory
: Octicons.file_submodule, : Octicons.file_submodule,
color: _iconDefaultColor, color: _iconDefaultColor,
size: 20, size: 24,
), );
SizedBox(width: 10),
];
default: default:
return []; throw 'Should not be here';
} }
} }
@ -91,15 +84,13 @@ class ObjectScreen extends StatelessWidget {
Widget _buildTree(payload) { Widget _buildTree(payload) {
var entries = payload['entries'] as List; var entries = payload['entries'] as List;
return Column( return TableView(
crossAxisAlignment: CrossAxisAlignment.stretch, items: entries.map((item) {
children: join( return TableViewItem(
borderView, leftWidget: _buildIcon(item),
entries.map((item) { text: Text(item['name']),
return Link( screenBuilder: (_) {
screenBuilder: item['type'] == 'commit' if (item['type'] == 'commit') return null;
? null
: (context) {
// TODO: All image types // TODO: All image types
var ext = path.extension(item['name']); var ext = path.extension(item['name']);
if (ext.isNotEmpty) ext = ext.substring(1); if (ext.isNotEmpty) ext = ext.substring(1);
@ -113,22 +104,8 @@ class ObjectScreen extends StatelessWidget {
paths: [...paths, item['name']], paths: [...paths, item['name']],
type: item['type'], type: item['type'],
); );
}, });
child: Container( }),
height: 40,
child: Row(
children: <Widget>[
..._buildIcon(item),
Expanded(
child: Text(item['name'],
style: TextStyle(
fontSize: 16, color: PrimerColors.gray900)))
],
),
),
);
}).toList(),
),
); );
} }
@ -148,6 +125,7 @@ class ObjectScreen extends StatelessWidget {
language: extname.isEmpty ? 'plaintext' : extname, language: extname.isEmpty ? 'plaintext' : extname,
theme: githubTheme, theme: githubTheme,
padding: EdgeInsets.all(10), padding: EdgeInsets.all(10),
textStyle: TextStyle(fontFamily: monospaceFont),
), ),
); );
} }

View File

@ -147,7 +147,7 @@ class BorderView extends StatelessWidget {
const BorderView({ const BorderView({
this.height = 1, this.height = 1,
this.color = PrimerColors.gray200, this.color = PrimerColors.gray100,
this.leftPadding = 0, this.leftPadding = 0,
}); });

View File

@ -24,7 +24,7 @@ class TableViewItem {
final bool hideRightChevron; final bool hideRightChevron;
TableViewItem({ TableViewItem({
this.text, @required this.text,
this.leftIconData, this.leftIconData,
this.leftWidget, this.leftWidget,
this.rightWidget, this.rightWidget,
@ -36,22 +36,14 @@ class TableViewItem {
class TableView extends StatelessWidget { class TableView extends StatelessWidget {
final String headerText; final String headerText;
final List<TableViewItem> items; final Iterable<TableViewItem> items;
TableView({this.headerText, @required this.items}); TableView({this.headerText, @required this.items});
Widget _buildItem(TableViewItem item) { Widget _buildItem(TableViewItem item) {
if (item == null) return null; if (item == null) return null;
var widget = DefaultTextStyle( var leftWidget = item.leftWidget ?? Icon(item.leftIconData);
style: TextStyle(fontSize: 16, color: PrimerColors.gray900),
overflow: TextOverflow.ellipsis,
child: Container(
height: 44,
child: Row(children: [
if (item.leftIconData != null) ...[
SizedBox(width: 12),
Icon(item.leftIconData),
// Container( // Container(
// width: 24, // width: 24,
// height: 24, // height: 24,
@ -59,19 +51,22 @@ class TableView extends StatelessWidget {
// // borderRadius: BorderRadius.circular(4), color: PrimerColors.blue400), // // borderRadius: BorderRadius.circular(4), color: PrimerColors.blue400),
// child: Icon(iconData, size: 24, color: PrimerColors.gray600), // child: Icon(iconData, size: 24, color: PrimerColors.gray600),
// ) // )
],
if (item.leftWidget != null) ...[ var widget = DefaultTextStyle(
SizedBox(width: 12), style: TextStyle(fontSize: 16, color: PrimerColors.gray900),
item.leftWidget, overflow: TextOverflow.ellipsis,
], child: SizedBox(
SizedBox(width: 12), height: 44,
child: Row(children: [
SizedBox(width: 44, child: leftWidget),
Expanded(child: item.text), Expanded(child: item.text),
if (item.rightWidget != null) item.rightWidget, if (item.rightWidget != null) item.rightWidget,
if ((item.onTap != null || item.screenBuilder != null) & if ((item.onTap != null || item.screenBuilder != null) &&
!item.hideRightChevron) !item.hideRightChevron) ...[
Icon(CupertinoIcons.right_chevron, Icon(CupertinoIcons.right_chevron,
size: 24, color: PrimerColors.gray400), size: 24, color: PrimerColors.gray300),
SizedBox(width: 4), SizedBox(width: 4),
],
]), ]),
), ),
); );