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

69 lines
2.2 KiB
Dart
Raw Normal View History

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