Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,47 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
part 'bitbucket.g.dart'; | ||
|
||
@JsonSerializable(fieldRename: FieldRename.snake) | ||
class BbPagination { | ||
int pagelen; | ||
int size; | ||
int page; | ||
String next; | ||
List values; | ||
BbPagination(); | ||
factory BbPagination.fromJson(Map<String, dynamic> json) => | ||
_$BbPaginationFromJson(json); | ||
} | ||
|
||
@JsonSerializable(fieldRename: FieldRename.snake) | ||
class BbUser { | ||
String username; | ||
String nickname; | ||
String displayName; | ||
String type; // user, team | ||
bool isStaff; | ||
DateTime createdOn; | ||
Map<String, dynamic> links; | ||
String get avatarUrl => links['avatar']['href']; | ||
BbUser(); | ||
factory BbUser.fromJson(Map<String, dynamic> json) => _$BbUserFromJson(json); | ||
} | ||
|
||
@JsonSerializable(fieldRename: FieldRename.snake) | ||
class BbRepo { | ||
String name; | ||
BbUser owner; | ||
String website; | ||
String language; | ||
int size; | ||
String type; // repository | ||
bool isPrivate; | ||
DateTime createdOn; | ||
DateTime updatedOn; | ||
String description; | ||
String fullName; | ||
Map<String, dynamic> links; | ||
String get avatarUrl => links['avatar']['href']; | ||
BbRepo(); | ||
factory BbRepo.fromJson(Map<String, dynamic> json) => _$BbRepoFromJson(json); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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'; | ||
import 'package:timeago/timeago.dart' as timeago; | ||
|
||
class BbUserScreen extends StatelessWidget { | ||
final String login; | ||
BbUserScreen(this.login); | ||
bool get isViewer => login == null; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return RefreshStatefulScaffold<Tuple2<BbUser, Iterable<BbRepo>>>( | ||
title: Text(isViewer ? 'Me' : 'User'), | ||
fetchData: () async { | ||
final auth = Provider.of<AuthModel>(context); | ||
final _login = login ?? auth.activeAccount.login; | ||
final res = await Future.wait([ | ||
auth.fetchBb('/users/$_login'), | ||
auth.fetchBbWithPage('/repositories/$_login'), | ||
]); | ||
return Tuple2( | ||
BbUser.fromJson(res[0]), | ||
[ | ||
for (var v in (res[1] as DataWithPage<List>).data) | ||
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( | ||
login: user.displayName, | ||
avatarUrl: user.avatarUrl, | ||
name: user.nickname, | ||
createdAt: user.createdOn, | ||
bio: null, | ||
), | ||
CommonStyle.border, | ||
Column( | ||
children: <Widget>[ | ||
for (var v in repos) | ||
RepositoryItem( | ||
owner: v.owner.displayName, | ||
name: v.name, | ||
url: '/bitbucket/${v.fullName}', | ||
avatarUrl: v.avatarUrl, | ||
avatarLink: '/bitbucket/${v.owner.displayName}', | ||
note: 'Updated ${timeago.format(v.updatedOn)}', | ||
description: v.description, | ||
forkCount: 0, | ||
starCount: 0, | ||
) | ||
], | ||
) | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |