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

58 lines
1.9 KiB
Dart
Raw Normal View History

2020-11-01 16:16:52 +01:00
import 'package:flutter/cupertino.dart';
import 'package:git_touch/models/gitee.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/object_tree.dart';
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
2020-11-01 16:16:52 +01:00
class GeTreeScreen extends StatelessWidget {
final String owner;
final String name;
final String sha;
GeTreeScreen(this.owner, this.name, this.sha);
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold<List<GiteeTreeItem>>(
2021-05-16 09:16:35 +02:00
title: AppBarTitle(AppLocalizations.of(context)!.files),
2020-11-01 16:16:52 +01:00
fetch: () async {
final res = await context
.read<AuthModel>()
.fetchGitee('/repos/$owner/$name/git/trees/$sha');
final items = [for (var v in res['tree']) GiteeTreeItem.fromJson(v)];
items.sort((a, b) {
return sortByKey('tree', a.type, b.type);
});
return items;
},
bodyBuilder: (data, _) {
return ObjectTree(
items: [
for (var item in data)
ObjectTreeItem(
type: item.type,
name: item.path,
size: item.size,
downloadUrl: '', // TODO:
url: (() {
switch (item.type) {
case 'tree':
2021-05-16 09:16:35 +02:00
return '/gitee/$owner/$name/tree/${item.sha}?path=${item.path!.urlencode}';
2020-11-01 16:16:52 +01:00
case 'blob':
2021-05-16 09:16:35 +02:00
return '/gitee/$owner/$name/blob/${item.sha}?path=${item.path!.urlencode}';
2020-11-01 16:16:52 +01:00
default:
return null;
}
})(),
)
],
);
},
);
}
}