2022-09-20 20:00:03 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2020-11-01 16:16:52 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2022-09-13 17:52:35 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
2020-11-01 16:16:52 +01:00
|
|
|
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:provider/provider.dart';
|
|
|
|
|
|
|
|
class GeTreeScreen extends StatelessWidget {
|
2022-09-21 18:28:21 +02:00
|
|
|
const GeTreeScreen(this.owner, this.name, this.sha);
|
2020-11-01 16:16:52 +01:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
final String 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, _) {
|
2022-09-20 20:00:03 +02:00
|
|
|
return AntList(
|
2022-09-22 17:37:06 +02:00
|
|
|
children: [
|
2020-11-01 16:16:52 +01:00
|
|
|
for (var item in data)
|
2022-09-13 17:52:35 +02:00
|
|
|
createObjectTreeItem(
|
2020-11-01 16:16:52 +01:00
|
|
|
type: item.type,
|
|
|
|
name: item.path,
|
|
|
|
size: item.size,
|
|
|
|
downloadUrl: '', // TODO:
|
2022-09-13 17:52:35 +02:00
|
|
|
url: item.type == 'tree'
|
|
|
|
? '/gitee/$owner/$name/tree/${item.sha}?path=${item.path.urlencode}'
|
|
|
|
: item.type == 'blob'
|
|
|
|
? '/gitee/$owner/$name/blob/${item.sha}?path=${item.path.urlencode}'
|
|
|
|
: '',
|
2020-11-01 16:16:52 +01:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|