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(context) .fetchGitlab('/users?username=$username'); final user = items[0]; final projects = await Provider.of(context) .fetchGitlab('/users/${user['id']}/projects') as List; final langs = await Future.wait(projects.map((p) => Provider.of(context) .fetchGitlab('/projects/${p['id']}/languages'))); for (var i = 0; i < projects.length; i++) { projects[i]['language'] = langs[i]; } return [user, projects]; }, bodyBuilder: (data, _) { final user = data[0]; final projects = data[1] as List; return Column( children: [ UserItem( login: user['username'], avatarUrl: user['avatar_url'], name: user['name'], ), BorderView(height: 10), Column( children: projects.map((project) { return RepositoryItem.gitlab(project); }).toList(), ) ], ); }, ); } }