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

54 lines
1.7 KiB
Dart
Raw Normal View History

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
GtUsersScreen.followers(String login)
2020-10-05 12:08:14 +02:00
: api = '/users/$login/followers',
title = 'Followers';
GtUsersScreen.following(String login)
2020-10-05 12:08:14 +02:00
: api = '/users/$login/following',
title = "Following";
GtUsersScreen.member(String login)
2020-10-05 12:08:14 +02:00
: api = '/orgs/$login/members',
title = "Members";
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),
fetch: (page) async {
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}',
);
},
);
}
}