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

56 lines
1.6 KiB
Dart
Raw Permalink Normal View History

2022-09-17 16:35:45 +02:00
import 'package:antd_mobile/antd_mobile.dart';
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';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2020-01-30 05:55:55 +01:00
import 'package:git_touch/utils/utils.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
2022-09-17 16:35:45 +02:00
return FileIcon(name, size: 26); // TODO: size
2022-09-13 17:52:35 +02:00
case 'tree': // github gql, gitlab
case 'dir': // github rest, gitea
case 'commit_directory': // bitbucket
2022-09-17 16:35:45 +02:00
return const Icon(AntIcons.folderOutline);
2022-09-13 17:52:35 +02:00
case 'commit':
2022-09-17 16:35:45 +02:00
return const Icon(AntIcons.fileOutline);
2022-09-13 17:52:35 +02:00
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-20 20:00:03 +02:00
AntListItem createObjectTreeItem({
2022-09-13 17:52:35 +02:00
required String name,
required String type,
required String url,
String? downloadUrl,
int? size,
}) {
2022-09-20 20:00:03 +02:00
return AntListItem(
2022-09-13 19:19:52 +02:00
prefix: _buildIcon(type, name),
extra: size == null ? null : Text(filesize(size)),
2022-09-20 20:00:03 +02:00
onClick: () async {
final finalUrl = [
// 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-20 20:00:03 +02:00
// Docs
'pdf', 'docx', 'doc', 'pptx', 'ppt', 'xlsx', 'xls',
// Fonts
'ttf', 'otf', 'eot', 'woff', 'woff2',
'svg',
].contains(name.ext)
? downloadUrl
: url;
await launchStringUrl(finalUrl);
},
arrow: size == null ? const Icon(AntIcons.rightOutline) : null,
2022-09-22 19:50:45 +02:00
child: Text(name),
2022-09-13 17:52:35 +02:00
);
2020-01-30 05:55:55 +01:00
}