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-11 16:09:39 +01:00
|
|
|
return RefreshStatefulScaffold<
|
|
|
|
Tuple2<GitlabUser, Iterable<GitlabUserProject>>>(
|
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');
|
2019-12-08 13:08:50 +01:00
|
|
|
final projects =
|
2019-12-11 16:09:39 +01:00
|
|
|
(v1 as List).map((v) => GitlabUserProject.fromJson(v)).toList();
|
2019-12-04 15:00:39 +01:00
|
|
|
|
2019-12-08 13:08:50 +01:00
|
|
|
return Tuple2(user, projects);
|
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;
|
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(
|
2019-12-08 13:08:50 +01:00
|
|
|
children: projects.map((v) => RepositoryItem.gitlab(v)).toList(),
|
2019-11-01 18:48:42 +01:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|