1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-05 18:27:33 +01:00

81 lines
2.2 KiB
Dart
Raw Normal View History

2020-01-30 15:31:46 +08:00
import 'package:filesize/filesize.dart';
2020-01-30 12:55:55 +08:00
import 'package:flutter/material.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/table_view.dart';
import 'package:primer/primer.dart';
import 'package:seti/seti.dart';
class ObjectTreeItem {
final String url;
2020-01-31 16:40:20 +08:00
final String downloadUrl;
2020-01-30 12:55:55 +08:00
final String name;
final String type;
2020-01-30 15:31:46 +08:00
final int size;
2020-01-30 12:55:55 +08:00
ObjectTreeItem({
@required this.name,
@required this.url,
2020-01-31 16:40:20 +08:00
@required this.downloadUrl,
2020-01-30 12:55:55 +08:00
@required this.type,
2020-01-30 15:31:46 +08:00
this.size,
2020-01-30 12:55:55 +08:00
});
}
class ObjectTree extends StatelessWidget {
final Iterable<ObjectTreeItem> items;
ObjectTree({@required this.items});
Widget _buildIcon(ObjectTreeItem item) {
switch (item.type) {
case 'blob': // github gql, gitlab
case 'file': // github rest, gitea
2020-01-30 12:55:55 +08:00
return SetiIcon(item.name, size: 36);
case 'tree': // github gql, gitlab
case 'dir': // github rest, gitea
2020-01-30 12:55:55 +08:00
return Icon(
Octicons.file_directory,
color: PrimerColors.blue300,
size: 24,
);
case 'commit':
return Icon(
Octicons.file_submodule,
color: PrimerColors.blue300,
size: 24,
);
default:
throw 'object type error';
}
}
@override
Widget build(BuildContext context) {
return TableView(
hasIcon: true,
items: [
for (var item in items)
TableViewItem(
leftWidget: _buildIcon(item),
text: Text(item.name),
2020-01-30 15:31:46 +08:00
rightWidget: item.size == null ? null : Text(filesize(item.size)),
2020-01-31 16:40:20 +08:00
url: [
// Let system browser handle these files
//
// TODO:
// Unhandled Exception: PlatformException(Error, Error while launching
// https://github.com/flutter/flutter/issues/49162
// Docs
'pdf', 'docx', 'doc', 'pptx', 'ppt', 'xlsx', 'xls',
// Fonts
'ttf', 'otf', 'eot', 'woff', 'woff2',
2020-01-31 16:43:40 +08:00
'svg',
2020-01-31 16:40:20 +08:00
].contains(item.name.ext)
? item.downloadUrl
: item.url,
2020-01-30 15:31:46 +08:00
hideRightChevron: item.size != null,
2020-01-30 12:55:55 +08:00
)
],
);
}
}