2022-09-20 20:00:03 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2020-05-14 07:28:12 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2022-09-11 19:54:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
2020-05-14 07:28:12 +02:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
|
|
|
import 'package:git_touch/widgets/object_tree.dart';
|
2022-10-01 18:29:54 +02:00
|
|
|
import 'package:gql_github/gist.data.gql.dart';
|
|
|
|
import 'package:gql_github/gist.req.gql.dart';
|
2020-05-14 07:28:12 +02:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class GhGistsFilesScreen extends StatelessWidget {
|
2022-09-21 18:28:21 +02:00
|
|
|
const GhGistsFilesScreen(this.login, this.id);
|
2020-05-14 07:28:12 +02:00
|
|
|
final String id;
|
|
|
|
final String login;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-05-16 09:16:35 +02:00
|
|
|
return RefreshStatefulScaffold<GGistData_user_gist?>(
|
|
|
|
title: AppBarTitle(AppLocalizations.of(context)!.files),
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: () async {
|
2021-01-31 15:08:37 +01:00
|
|
|
final req = GGistReq((b) => b
|
|
|
|
..vars.login = login
|
|
|
|
..vars.name = id);
|
2022-09-30 21:49:56 +02:00
|
|
|
final res =
|
2022-10-01 19:26:34 +02:00
|
|
|
await context.read<AuthModel>().ghGqlClient.request(req).first;
|
2021-05-16 09:16:35 +02:00
|
|
|
final gist = res.data!.user!.gist;
|
2021-01-31 15:08:37 +01:00
|
|
|
return gist;
|
2020-05-14 07:28:12 +02:00
|
|
|
},
|
|
|
|
bodyBuilder: (payload, _) {
|
2022-09-20 20:00:03 +02:00
|
|
|
return AntList(
|
2022-09-22 17:37:06 +02:00
|
|
|
children: payload!.files!.map((v) {
|
2020-05-14 07:28:12 +02:00
|
|
|
final uri = Uri(
|
2021-01-31 15:08:37 +01:00
|
|
|
path: '/github/$login/gists/$id/${v.name}',
|
2020-05-14 07:28:12 +02:00
|
|
|
queryParameters: {
|
2021-01-31 15:08:37 +01:00
|
|
|
'content': v.text,
|
2020-05-14 07:28:12 +02:00
|
|
|
},
|
|
|
|
).toString();
|
2022-09-13 17:52:35 +02:00
|
|
|
return createObjectTreeItem(
|
2020-05-14 07:28:12 +02:00
|
|
|
url: uri,
|
|
|
|
type: 'file',
|
2021-06-14 05:28:12 +02:00
|
|
|
name: v.name ?? '',
|
2021-01-31 15:08:37 +01:00
|
|
|
downloadUrl: null,
|
2020-05-14 07:28:12 +02:00
|
|
|
size: v.size,
|
|
|
|
);
|
2022-09-20 20:00:03 +02:00
|
|
|
}).toList(),
|
2020-05-14 07:28:12 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|