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

70 lines
2.4 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';
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';
class GitlabUserScreen extends StatelessWidget {
final String username;
GitlabUserScreen(this.username);
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold(
title: Text('User'),
fetchData: () async {
final items = await Provider.of<AuthModel>(context)
.fetchGitlab('/users?username=$username');
final user = items[0];
final projects = await Provider.of<AuthModel>(context)
.fetchGitlab('/users/${user['id']}/projects') as List;
final langs = await Future.wait(projects.map((p) =>
Provider.of<AuthModel>(context)
.fetchGitlab('/projects/${p['id']}/languages')));
for (var i = 0; i < projects.length; i++) {
projects[i]['language'] = langs[i];
}
return [user, projects];
},
bodyBuilder: (payload) {
final data = payload.data[0];
final projects = payload.data[1] as List;
return Column(
children: <Widget>[
UserItem(
login: data['username'],
avatarUrl: data['avatar_url'],
name: data['name'],
),
BorderView(height: 10),
Column(
children: projects.map((project) {
return RepositoryItem({
'owner': {
'__typename': 'user',
'login': project['owner']['name'],
'avatarUrl': project['owner']['avatar_url'],
},
'name': project['name'],
'description': project['description'],
'isPrivate': project['visibility'] == 'private',
'isFork': false,
'stargazers': {'totalCount': project['star_count']},
'forks': {
'totalCount': project['forks_count'],
},
'primaryLanguage': null
});
}).toList(),
)
],
);
},
);
}
}