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

73 lines
1.9 KiB
Dart
Raw Normal View History

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';
2020-02-10 12:25:25 +01:00
import 'package:file_icon/file_icon.dart';
2020-01-30 05:55:55 +01:00
class ObjectTreeItem extends StatelessWidget {
final String type;
final String name;
final int? size;
2021-05-16 09:16:35 +02:00
final String? url;
final String? downloadUrl;
const ObjectTreeItem({
2021-05-16 09:16:35 +02:00
required this.type,
required this.name,
2020-01-30 08:31:46 +01:00
this.size,
this.url,
this.downloadUrl,
2020-01-30 05:55:55 +01:00
});
Widget _buildIcon() {
switch (type) {
case 'blob': // github gql, gitlab
case 'file': // github rest, gitea
2020-02-02 12:50:00 +01:00
case 'commit_file': // bitbucket
return FileIcon(name, size: 36);
case 'tree': // github gql, gitlab
case 'dir': // github rest, gitea
2020-02-02 12:50:00 +01:00
case 'commit_directory': // bitbucket
2022-09-06 18:28:12 +02:00
return const Icon(
2020-01-30 05:55:55 +01:00
Octicons.file_directory,
color: PrimerColors.blue300,
size: 24,
);
case 'commit':
2022-09-06 18:28:12 +02:00
return const Icon(
2020-01-30 05:55:55 +01:00
Octicons.file_submodule,
color: PrimerColors.blue300,
size: 24,
);
default:
throw 'object type error';
}
}
@override
Widget build(BuildContext context) {
return TableViewItem(
leftWidget: _buildIcon(),
text: Text(name),
rightWidget: size == null ? null : Text(filesize(size)),
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
// 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
);
}
}