2020-01-30 08:31:46 +01:00
|
|
|
import 'package:filesize/filesize.dart';
|
2020-01-30 05:55:55 +01: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;
|
|
|
|
final String name;
|
|
|
|
final String type;
|
2020-01-30 08:31:46 +01:00
|
|
|
final int size;
|
2020-01-30 05:55:55 +01:00
|
|
|
ObjectTreeItem({
|
|
|
|
@required this.name,
|
|
|
|
@required this.url,
|
|
|
|
@required this.type,
|
2020-01-30 08:31:46 +01:00
|
|
|
this.size,
|
2020-01-30 05:55:55 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class ObjectTree extends StatelessWidget {
|
|
|
|
final Iterable<ObjectTreeItem> items;
|
|
|
|
ObjectTree({@required this.items});
|
|
|
|
|
|
|
|
Widget _buildIcon(ObjectTreeItem item) {
|
|
|
|
switch (item.type) {
|
|
|
|
case 'blob':
|
2020-01-30 08:04:29 +01:00
|
|
|
case 'file': // Gitea
|
2020-01-30 05:55:55 +01:00
|
|
|
return SetiIcon(item.name, size: 36);
|
|
|
|
case 'tree':
|
2020-01-30 08:04:29 +01:00
|
|
|
case 'dir': // Gitea
|
2020-01-30 05:55:55 +01: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 08:31:46 +01:00
|
|
|
rightWidget: item.size == null ? null : Text(filesize(item.size)),
|
2020-01-30 05:55:55 +01:00
|
|
|
url: item.url,
|
2020-01-30 08:31:46 +01:00
|
|
|
hideRightChevron: item.size != null,
|
2020-01-30 05:55:55 +01:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|