git-touch-android-ios-app/lib/widgets/object_tree.dart

62 lines
1.6 KiB
Dart
Raw Normal View History

2022-09-13 17:52:35 +02:00
import 'package:file_icon/file_icon.dart';
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';
2022-09-13 17:52:35 +02:00
Widget _buildIcon(String type, String name) {
switch (type) {
case 'blob': // github gql, gitlab
case 'file': // github rest, gitea
case 'commit_file': // bitbucket
return FileIcon(name, size: 36);
case 'tree': // github gql, gitlab
case 'dir': // github rest, gitea
case 'commit_directory': // bitbucket
return const Icon(
Octicons.file_directory,
color: PrimerColors.blue300,
size: 24,
);
case 'commit':
return const Icon(
Octicons.file_submodule,
color: PrimerColors.blue300,
size: 24,
);
default:
throw 'object type error';
2020-01-30 05:55:55 +01:00
}
2022-09-13 17:52:35 +02:00
}
2020-01-30 05:55:55 +01:00
2022-09-13 17:52:35 +02:00
TableViewItem createObjectTreeItem({
required String name,
required String type,
required String url,
String? downloadUrl,
int? size,
}) {
return TableViewItem(
2022-09-13 19:19:52 +02:00
prefix: _buildIcon(type, name),
child: Text(name),
extra: size == null ? null : Text(filesize(size)),
2022-09-13 17:52:35 +02:00
url: [
// Let system browser handle these files
//
// TODO:
// Unhandled Exception: PlatformException(Error, Error while launching
// https://github.com/flutter/flutter/issues/49162
2020-01-31 09:40:20 +01:00
2022-09-13 17:52:35 +02:00
// Docs
'pdf', 'docx', 'doc', 'pptx', 'ppt', 'xlsx', 'xls',
// Fonts
'ttf', 'otf', 'eot', 'woff', 'woff2',
'svg',
].contains(name.ext)
? downloadUrl
: url,
hideRightChevron: size != null,
);
2020-01-30 05:55:55 +01:00
}