git-touch-android-ios-app/lib/screens/ge_user.dart

122 lines
4.0 KiB
Dart
Raw Normal View History

2020-10-17 11:35:08 +02:00
import 'package:flutter/cupertino.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2022-10-07 18:55:47 +02:00
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2022-09-17 14:35:45 +02:00
import 'package:git_touch/models/auth.dart';
2020-10-17 11:35:08 +02:00
import 'package:git_touch/models/gitee.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
2022-09-17 14:35:45 +02:00
import 'package:git_touch/widgets/action_button.dart';
2020-10-17 11:35:08 +02:00
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/entry_item.dart';
2022-10-02 06:49:55 +02:00
import 'package:git_touch/widgets/repo_item.dart';
2020-10-17 11:35:08 +02:00
import 'package:git_touch/widgets/user_header.dart';
import 'package:provider/provider.dart';
import 'package:timeago/timeago.dart' as timeago;
2022-09-17 14:35:45 +02:00
import 'package:tuple/tuple.dart';
2020-10-17 11:35:08 +02:00
class GeUserScreen extends StatelessWidget {
2022-09-21 18:28:21 +02:00
const GeUserScreen(this.login, {this.isViewer = false});
2020-10-17 11:35:08 +02:00
final String login;
final bool isViewer;
@override
Widget build(BuildContext context) {
final auth = Provider.of<AuthModel>(context);
return RefreshStatefulScaffold<Tuple2<GiteeUser, List<GiteeRepo>>>(
fetch: () async {
final res = await Future.wait([
auth.fetchGitee('/users/$login'),
auth.fetchGitee('/users/$login/repos?per_page=6'),
]);
return Tuple2(
GiteeUser.fromJson(res[0]),
[for (var v in res[1]) GiteeRepo.fromJson(v)],
);
},
2022-10-07 19:06:03 +02:00
title: Text(isViewer ? 'Me' : login),
2020-10-17 11:35:08 +02:00
action: isViewer
2022-09-06 18:28:12 +02:00
? const ActionEntry(
2021-02-14 15:17:22 +01:00
iconData: Ionicons.cog,
2020-10-17 11:35:08 +02:00
url: '/settings',
)
: null,
actionBuilder: isViewer
? null
2021-01-31 08:49:28 +01:00
: (p, _) {
2020-10-17 11:35:08 +02:00
return ActionButton(
title: 'User Actions',
items: [...ActionItem.getUrlActions(p.item1.htmlUrl)],
);
},
2021-01-31 08:49:28 +01:00
bodyBuilder: (p, _) {
2020-10-17 11:35:08 +02:00
final user = p.item1;
final repos = p.item2;
return Column(
children: <Widget>[
UserHeader(
login: user.login,
avatarUrl: user.avatarUrl,
name: user.name,
createdAt: user.createdAt,
isViewer: isViewer,
bio: user.bio,
),
CommonStyle.border,
Row(children: [
EntryItem(
2022-10-04 14:18:04 +02:00
count: user.publicRepos!,
2020-10-17 11:35:08 +02:00
text: 'Repositories',
url: '/gitee/$login?tab=repositories',
),
EntryItem(
2022-10-04 14:18:04 +02:00
count: user.stared!,
2020-10-17 11:35:08 +02:00
text: 'Stars',
url: '/gitee/$login?tab=stars',
),
EntryItem(
2022-10-04 14:18:04 +02:00
count: user.followers!,
2020-10-17 11:35:08 +02:00
text: 'Followers',
url: '/gitee/$login?tab=followers',
),
EntryItem(
2022-10-04 14:18:04 +02:00
count: user.following!,
2020-10-17 11:35:08 +02:00
text: 'Following',
url: '/gitee/$login?tab=following',
),
]),
2022-09-20 20:00:03 +02:00
// AntList(
2020-10-17 11:35:08 +02:00
// hasIcon: true,
// items: [
2022-09-20 20:00:03 +02:00
// AntListItem(
2020-10-17 11:35:08 +02:00
// leftIconData: Octicons.home,
// text: Text('Organizations'),
2020-10-17 13:06:11 +02:00
// url: '/gitee/$login?tab=organizations',
2020-10-17 11:35:08 +02:00
// ),
// ],
// ),
CommonStyle.border,
Column(
children: <Widget>[
for (var v in repos)
2022-10-02 06:49:55 +02:00
RepoItem(
2021-05-16 09:16:35 +02:00
owner: v.namespace!.path,
avatarUrl: v.owner!.avatarUrl,
2020-10-17 11:35:08 +02:00
name: v.path,
description: v.description,
starCount: v.stargazersCount,
forkCount: v.forksCount,
2021-05-16 09:16:35 +02:00
note: 'Updated ${timeago.format(v.updatedAt!)}',
url: '/gitee/${v.namespace!.path}/${v.path}',
avatarLink: '/gitee/${v.namespace!.path}',
2020-10-17 11:35:08 +02:00
// iconData: , TODO:
)
],
),
],
);
},
);
}
}