2020-04-25 12:31:32 +02:00
|
|
|
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/models/auth.dart';
|
2020-04-25 12:31:32 +02:00
|
|
|
import 'package:git_touch/models/github.dart';
|
|
|
|
import 'package:git_touch/scaffolds/list_stateful.dart';
|
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
|
|
|
import 'package:git_touch/widgets/contributor_item.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class GhContributorsScreen extends StatelessWidget {
|
2022-09-21 18:28:21 +02:00
|
|
|
const GhContributorsScreen(this.owner, this.name);
|
2020-04-25 12:31:32 +02:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
|
2022-09-06 18:28:12 +02:00
|
|
|
@override
|
2020-04-25 12:31:32 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListStatefulScaffold<GithubContributorItem, int>(
|
2021-05-16 09:16:35 +02:00
|
|
|
title: AppBarTitle(AppLocalizations.of(context)!.contributors),
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: (page) async {
|
2020-10-04 16:10:05 +02:00
|
|
|
page = page ?? 1;
|
|
|
|
final res = await context
|
|
|
|
.read<AuthModel>()
|
2021-06-14 08:56:42 +02:00
|
|
|
.ghClient
|
2020-10-04 16:10:05 +02:00
|
|
|
.getJSON<List, List<GithubContributorItem>>(
|
|
|
|
'/repos/$owner/$name/contributors?page=$page',
|
|
|
|
convert: (vs) =>
|
|
|
|
[for (var v in vs) GithubContributorItem.fromJson(v)],
|
|
|
|
);
|
|
|
|
return ListPayload(
|
|
|
|
cursor: page + 1,
|
|
|
|
items: res,
|
|
|
|
hasMore: res.isNotEmpty,
|
|
|
|
);
|
|
|
|
},
|
2020-04-25 12:31:32 +02:00
|
|
|
itemBuilder: (v) {
|
2021-05-16 09:16:35 +02:00
|
|
|
final String? login = v.login;
|
2020-04-25 12:31:32 +02:00
|
|
|
return ContributorItem(
|
|
|
|
avatarUrl: v.avatarUrl,
|
|
|
|
commits: v.contributions,
|
|
|
|
login: v.login,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$login?tab=contributors',
|
2020-04-25 12:31:32 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|