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

64 lines
2.0 KiB
Dart
Raw Normal View History

2020-01-30 08:04:29 +01:00
import 'package:flutter/material.dart';
import 'package:git_touch/generated/l10n.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: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;
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(
title: AppBarTitle(path ?? S.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;
},
actionBuilder: (p, _) {
if (p is List) {
return null;
} else {
return ActionEntry(
iconData: Icons.settings,
2020-01-31 09:54:01 +01:00
url: '/choose-code-theme',
2020-01-30 08:04:29 +01:00
);
}
},
bodyBuilder: (p, _) {
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 ObjectTree(items: [
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,
2020-01-30 08:04:29 +01: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);
}
},
);
}
}