1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-15 11:00:45 +01:00

72 lines
2.3 KiB
Dart
Raw Normal View History

2020-02-02 16:40:12 +08:00
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/bitbucket.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/repository_item.dart';
import 'package:git_touch/widgets/user_header.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
import 'package:git_touch/utils/utils.dart';
class BbUserScreen extends StatelessWidget {
2021-05-16 15:16:35 +08:00
final String? login;
2020-02-02 22:43:01 +08:00
final bool isTeam;
BbUserScreen(this.login, {this.isTeam = false});
2020-02-02 16:40:12 +08:00
bool get isViewer => login == null;
@override
Widget build(BuildContext context) {
2020-02-02 19:06:48 +08:00
final auth = Provider.of<AuthModel>(context);
2021-05-16 15:16:35 +08:00
final _accountId = auth.activeAccount!.accountId;
final _login = login ?? auth.activeAccount!.login;
2020-02-02 16:40:12 +08:00
return RefreshStatefulScaffold<Tuple2<BbUser, Iterable<BbRepo>>>(
2020-10-04 20:37:23 +08:00
title: Text(isViewer
? 'Me'
: isTeam
? 'Team'
: 'User'),
fetch: () async {
2020-02-02 16:40:12 +08:00
final res = await Future.wait([
2021-06-14 14:02:52 +08:00
auth
.fetchBbJson('/${isTeam ? 'teams' : 'users'}/$_accountId')
.then((value) => BbUser.fromJson(value)),
auth
.fetchBbWithPage('/repositories/$_login')
.then((value) => [for (var v in value.items) BbRepo.fromJson(v)]),
2020-02-02 16:40:12 +08:00
]);
2021-06-14 14:02:52 +08:00
return Tuple2(res[0] as BbUser, res[1] as Iterable<BbRepo>);
2020-02-02 16:40:12 +08:00
},
action: isViewer
? ActionEntry(
2021-02-14 22:17:22 +08:00
iconData: Ionicons.cog,
2020-02-02 16:40:12 +08:00
url: '/settings',
)
: null,
bodyBuilder: (data, _) {
final user = data.item1;
final repos = data.item2;
return Column(
children: <Widget>[
UserHeader(
2020-02-02 19:06:48 +08:00
login: _login,
2020-02-02 16:40:12 +08:00
avatarUrl: user.avatarUrl,
2020-02-02 19:06:48 +08:00
name: user.displayName,
2020-02-02 16:40:12 +08:00
createdAt: user.createdOn,
isViewer: isViewer,
2020-02-02 16:40:12 +08:00
bio: null,
),
CommonStyle.border,
Column(
children: <Widget>[
2020-02-02 17:30:48 +08:00
for (var v in repos) RepositoryItem.bb(payload: v)
2020-02-02 16:40:12 +08:00
],
)
],
);
},
);
}
}