1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-19 11:43:30 +01:00
git-touch-android-ios-app/lib/screens/gitlab/user.dart

60 lines
1.9 KiB
Dart
Raw Normal View History

2019-11-01 18:48:42 +01:00
import 'package:flutter/widgets.dart';
import 'package:git_touch/models/auth.dart';
2019-12-04 15:00:39 +01:00
import 'package:git_touch/models/gitlab.dart';
2019-11-01 18:48:42 +01:00
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/widgets/border_view.dart';
import 'package:git_touch/widgets/repository_item.dart';
import 'package:git_touch/widgets/user_item.dart';
import 'package:provider/provider.dart';
2019-12-04 15:00:39 +01:00
import 'package:tuple/tuple.dart';
2019-11-01 18:48:42 +01:00
class GitlabUserScreen extends StatelessWidget {
final String username;
GitlabUserScreen(this.username);
@override
Widget build(BuildContext context) {
2019-12-04 15:00:39 +01:00
return RefreshStatefulScaffold<
Tuple3<GitlabUser, Iterable<GitlabRepository>,
List<Map<String, double>>>>(
2019-11-01 18:48:42 +01:00
title: Text('User'),
fetchData: () async {
2019-12-04 15:00:39 +01:00
final auth = Provider.of<AuthModel>(context);
final v0 = await auth.fetchGitlab('/users?username=$username');
final user = GitlabUser.fromJson(v0[0]);
final v1 = await auth.fetchGitlab('/users/${user.id}/projects');
final projects = (v1 as List).map((v) => GitlabRepository.fromJson(v));
final languages = await Future.wait(projects
.map((p) => auth.fetchGitlab('/projects/${p.id}/languages')));
return Tuple3(user, projects, languages.cast<Map<String, double>>());
2019-11-01 18:48:42 +01:00
},
2019-11-02 13:54:23 +01:00
bodyBuilder: (data, _) {
2019-12-04 15:00:39 +01:00
final user = data.item1;
final projects = data.item2;
final languages = data.item3;
2019-11-01 18:48:42 +01:00
return Column(
children: <Widget>[
UserItem(
2019-12-04 15:00:39 +01:00
login: user.username,
avatarUrl: user.avatarUrl,
name: user.name,
2019-11-01 18:48:42 +01:00
),
BorderView(height: 10),
Column(
children: projects.map((project) {
2019-11-02 10:50:04 +01:00
return RepositoryItem.gitlab(project);
2019-11-01 18:48:42 +01:00
}).toList(),
)
],
);
},
);
}
}