2020-10-05 12:01:49 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:git_touch/models/gitea.dart';
|
|
|
|
import 'package:git_touch/scaffolds/list_stateful.dart';
|
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
|
|
|
import 'package:git_touch/widgets/user_item.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
|
|
|
|
|
|
|
class GtUsersScreen extends StatelessWidget {
|
|
|
|
final String api;
|
2020-10-05 12:08:14 +02:00
|
|
|
final String title;
|
2020-10-05 12:01:49 +02:00
|
|
|
|
2020-10-05 12:20:00 +02:00
|
|
|
GtUsersScreen.followers(String login)
|
2020-10-05 12:08:14 +02:00
|
|
|
: api = '/users/$login/followers',
|
|
|
|
title = 'Followers';
|
2020-10-05 12:20:00 +02:00
|
|
|
GtUsersScreen.following(String login)
|
2020-10-05 12:08:14 +02:00
|
|
|
: api = '/users/$login/following',
|
|
|
|
title = "Following";
|
2020-10-05 12:20:00 +02:00
|
|
|
GtUsersScreen.member(String login)
|
2020-10-05 12:08:14 +02:00
|
|
|
: api = '/orgs/$login/members',
|
|
|
|
title = "Members";
|
2020-10-05 12:20:00 +02:00
|
|
|
GtUsersScreen.stargazers(String owner, String repo)
|
|
|
|
: api = '/repos/$owner/$repo/stargazers',
|
|
|
|
title = 'Stargazers';
|
|
|
|
GtUsersScreen.watchers(String owner, String repo)
|
|
|
|
: api = '/repos/$owner/$repo/subscribers',
|
|
|
|
title = 'Watchers';
|
2020-10-05 12:01:49 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListStatefulScaffold<GiteaUser, int>(
|
2020-10-05 12:08:14 +02:00
|
|
|
title: AppBarTitle(title),
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: (page) async {
|
2020-10-06 05:54:35 +02:00
|
|
|
final res =
|
|
|
|
await context.read<AuthModel>().fetchGiteaWithPage(api, page: page);
|
2020-10-05 12:01:49 +02:00
|
|
|
return ListPayload(
|
|
|
|
cursor: res.cursor,
|
|
|
|
hasMore: res.hasMore,
|
|
|
|
items: [for (var v in res.data) GiteaUser.fromJson(v)],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemBuilder: (payload) {
|
|
|
|
return UserItem(
|
|
|
|
login: payload.login,
|
|
|
|
avatarUrl: payload.avatarUrl,
|
|
|
|
bio: Text('Joined on ${timeago.format(payload.created)}'),
|
|
|
|
url: '/gitea/${payload.login}',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|