git-touch-android-ios-app/lib/screens/gt_object.dart

65 lines
2.1 KiB
Dart
Raw Normal View History

2020-01-30 08:04:29 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
2020-01-30 08:04:29 +01:00
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitea.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/blob_view.dart';
import 'package:git_touch/widgets/object_tree.dart';
import 'package:git_touch/widgets/table_view.dart';
2020-01-30 08:04:29 +01:00
import 'package:provider/provider.dart';
2020-02-07 15:20:06 +01:00
class GtObjectScreen extends StatelessWidget {
2020-01-30 08:04:29 +01:00
final String owner;
final String name;
2021-05-16 09:16:35 +02:00
final String? path;
2020-02-07 15:20:06 +01:00
GtObjectScreen(this.owner, this.name, {this.path});
2020-01-30 08:04:29 +01:00
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold(
2021-05-16 09:16:35 +02:00
title: AppBarTitle(path ?? AppLocalizations.of(context)!.files),
fetch: () async {
2020-01-30 08:04:29 +01:00
final suffix = path == null ? '' : '/$path';
2020-10-04 14:37:23 +02:00
final res = await context
.read<AuthModel>()
2020-01-30 08:04:29 +01:00
.fetchGitea('/repos/$owner/$name/contents$suffix');
return res;
},
2021-05-16 09:16:35 +02:00
actionBuilder: (dynamic p, _) {
2020-01-30 08:04:29 +01:00
if (p is List) {
return null;
} else {
return ActionEntry(
2021-02-14 15:17:22 +01:00
iconData: Ionicons.cog,
2020-01-31 09:54:01 +01:00
url: '/choose-code-theme',
2020-01-30 08:04:29 +01:00
);
}
},
2021-05-16 09:16:35 +02:00
bodyBuilder: (dynamic p, _) {
2020-01-30 08:04:29 +01:00
if (p is List) {
2020-01-30 12:24:59 +01:00
final items = p.map((t) => GiteaTree.fromJson(t)).toList();
items.sort((a, b) {
return sortByKey('dir', a.type, b.type);
});
return TableView(items: [
2020-01-30 12:24:59 +01:00
for (var v in items)
ObjectTreeItem(
2020-01-30 08:04:29 +01:00
name: v.name,
type: v.type,
2020-01-30 08:31:46 +01:00
size: v.type == 'file' ? v.size : null,
2021-05-16 09:16:35 +02:00
url: '/gitea/$owner/$name/blob?path=${v.path!.urlencode}',
2020-01-31 09:40:20 +01:00
downloadUrl: v.downloadUrl,
2020-01-30 12:24:59 +01:00
),
]);
2020-01-30 08:04:29 +01:00
} else {
final v = GiteaBlob.fromJson(p);
return BlobView(v.name, base64Text: v.content);
}
},
);
}
}