2019-12-04 15:02:22 +01:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/gitea.dart';
|
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
2020-01-11 10:25:01 +01:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2019-12-04 15:02:22 +01:00
|
|
|
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';
|
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
|
|
|
|
class GiteaUserScreen extends StatelessWidget {
|
|
|
|
final String username;
|
|
|
|
|
|
|
|
GiteaUserScreen(this.username);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RefreshStatefulScaffold<
|
|
|
|
Tuple2<GiteaUser, Iterable<GiteaRepository>>>(
|
|
|
|
title: Text('User'),
|
|
|
|
fetchData: () async {
|
|
|
|
final auth = Provider.of<AuthModel>(context);
|
|
|
|
final items = await Future.wait([
|
|
|
|
auth.fetchGitea('/users/$username'),
|
|
|
|
auth.fetchGitea('/users/$username/repos'),
|
|
|
|
]);
|
|
|
|
return Tuple2(GiteaUser.fromJson(items[0]),
|
|
|
|
(items[1] as List).map((v) => GiteaRepository.fromJson(v)));
|
|
|
|
},
|
|
|
|
bodyBuilder: (data, _) {
|
|
|
|
final user = data.item1;
|
|
|
|
final repos = data.item2;
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
UserItem(
|
|
|
|
login: user.login,
|
|
|
|
avatarUrl: user.avatarUrl,
|
|
|
|
name: user.fullName,
|
|
|
|
),
|
|
|
|
BorderView(height: 10),
|
|
|
|
Column(
|
|
|
|
children: repos.map((v) {
|
2020-01-11 10:25:01 +01:00
|
|
|
return RepositoryItem(
|
|
|
|
v.owner.login,
|
|
|
|
v.owner.avatarUrl,
|
|
|
|
v.name,
|
|
|
|
v.description,
|
|
|
|
Octicons.repo,
|
|
|
|
v.starsCount,
|
|
|
|
v.forksCount,
|
|
|
|
null,
|
|
|
|
null,
|
2020-01-11 12:25:33 +01:00
|
|
|
null,
|
2020-01-11 10:25:01 +01:00
|
|
|
);
|
2019-12-04 15:02:22 +01:00
|
|
|
}).toList(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|