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

51 lines
1.8 KiB
Dart
Raw Normal View History

2021-05-16 09:16:35 +02:00
import 'package:ferry/ferry.dart';
import 'package:flutter/cupertino.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:git_touch/graphql/__generated__/github.data.gql.dart';
import 'package:git_touch/graphql/__generated__/github.req.gql.dart';
2022-09-06 18:00:51 +02:00
import 'package:git_touch/graphql/__generated__/github.var.gql.dart';
2022-09-17 14:35:45 +02:00
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/gists_item.dart';
import 'package:provider/provider.dart';
class GhGistsScreen extends StatelessWidget {
2022-09-06 18:28:12 +02:00
const GhGistsScreen(this.login);
2022-09-21 18:28:21 +02:00
final String login;
@override
Widget build(BuildContext context) {
2021-05-16 09:16:35 +02:00
return ListStatefulScaffold<GGistsData_user_gists_nodes, String?>(
title: AppBarTitle(AppLocalizations.of(context)!.gists),
fetch: (page) async {
final req = GGistsReq((b) => b
..vars.login = login
..vars.after = page);
2021-05-16 09:16:35 +02:00
final OperationResponse<GGistsData, GGistsVars?> res =
2021-06-14 08:56:42 +02:00
await context.read<AuthModel>().gqlClient.request(req).first;
2021-05-16 09:16:35 +02:00
final gists = res.data!.user!.gists;
2020-10-04 16:10:05 +02:00
return ListPayload(
cursor: gists.pageInfo.endCursor,
2021-06-13 19:23:16 +02:00
items: gists.nodes ?? [],
hasMore: gists.pageInfo.hasNextPage,
2020-10-04 16:10:05 +02:00
);
},
itemBuilder: (v) {
2021-05-16 09:16:35 +02:00
final filenames = [for (var file in v.files!) file.name];
// TODO: add gist comments
return GistsItem(
description: v.description,
login: login,
filenames: filenames,
2021-05-16 09:16:35 +02:00
language: v.files![0].language!.name,
avatarUrl: v.owner!.avatarUrl,
updatedAt: v.updatedAt,
id: v.name,
);
},
);
}
}