1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-24 06:42:07 +01:00
git-touch-android-ios-app/lib/screens/bb_user.dart

68 lines
2.1 KiB
Dart
Raw Normal View History

2020-02-02 09:40:12 +01: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 {
final String login;
2020-02-02 15:43:01 +01:00
final bool isTeam;
BbUserScreen(this.login, {this.isTeam = false});
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);
final _login = login ?? auth.activeAccount.login;
2020-02-02 09:40:12 +01:00
return RefreshStatefulScaffold<Tuple2<BbUser, Iterable<BbRepo>>>(
2020-02-02 15:43:01 +01:00
title: Text(isViewer ? 'Me' : isTeam ? 'Team' : 'User'),
2020-02-02 09:40:12 +01:00
fetchData: () async {
final res = await Future.wait([
2020-02-02 15:43:01 +01:00
auth.fetchBbJson('/${isTeam ? 'teams' : 'users'}/$_login'),
2020-02-02 09:40:12 +01:00
auth.fetchBbWithPage('/repositories/$_login'),
]);
return Tuple2(
BbUser.fromJson(res[0]),
[
2020-02-02 10:30:48 +01:00
for (var v in (res[1] as BbPagePayload<List>).data)
2020-02-02 09:40:12 +01:00
BbRepo.fromJson(v)
],
);
},
action: isViewer
? ActionEntry(
iconData: Icons.settings,
url: '/settings',
)
: null,
bodyBuilder: (data, _) {
final user = data.item1;
final repos = data.item2;
return Column(
children: <Widget>[
UserHeader(
2020-02-02 12:06:48 +01:00
login: _login,
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,
bio: null,
),
CommonStyle.border,
Column(
children: <Widget>[
2020-02-02 10:30:48 +01:00
for (var v in repos) RepositoryItem.bb(payload: v)
2020-02-02 09:40:12 +01:00
],
)
],
);
},
);
}
}