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

53 lines
1.5 KiB
Dart
Raw Normal View History

2020-02-01 05:14:03 +01:00
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitlab.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:provider/provider.dart';
import '../generated/l10n.dart';
2020-02-01 05:14:03 +01:00
2020-02-07 15:26:37 +01:00
class GlMembersScreen extends StatelessWidget {
2020-02-01 05:14:03 +01:00
final int id;
final String type;
2020-02-07 15:26:37 +01:00
GlMembersScreen(this.id, this.type);
2020-02-01 05:14:03 +01:00
// https://docs.gitlab.com/ee/api/access_requests.html#valid-access-levels
static const accessLevelMap = {
10: 'Guest',
20: 'Reporter',
30: 'Developer',
40: 'Maintainer',
50: 'Owner',
};
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GitlabUser, int>(
title: AppBarTitle(S.of(context).members),
fetch: (page) async {
2020-10-04 16:10:05 +02:00
page = page ?? 1;
final auth = context.read<AuthModel>();
final res =
await auth.fetchGitlabWithPage('/$type/$id/members?page=$page');
return ListPayload(
cursor: res.cursor,
hasMore: res.hasMore,
items: <GitlabUser>[
for (var v in res.data) GitlabUser.fromJson(v),
],
);
},
2020-02-01 05:14:03 +01:00
itemBuilder: (v) {
2020-10-08 09:55:26 +02:00
return UserItem.gitlab(
2020-02-01 05:14:03 +01:00
avatarUrl: v.avatarUrl,
login: v.username,
2020-10-08 09:55:26 +02:00
name: v.name,
2020-02-01 05:14:03 +01:00
bio: Text(accessLevelMap[v.accessLevel] ?? ''),
2020-10-08 09:55:26 +02:00
id: v.id,
2020-02-01 05:14:03 +01:00
);
},
);
}
}