fix: types

This commit is contained in:
Rongjian Zhang 2021-06-14 14:02:52 +08:00
parent 242dd1200d
commit 97bd998491
5 changed files with 27 additions and 20 deletions

View File

@ -11,7 +11,7 @@ import '../widgets/error_reload.dart';
class LongListPayload<T, K> {
T header;
int totalCount;
String cursor;
String? cursor;
List<K> leadingItems;
List<K>? trailingItems;

View File

@ -22,17 +22,21 @@ class BbIssueScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold<Tuple2<BbIssues, List<BbComment>>>(
return RefreshStatefulScaffold<Tuple2<BbIssues, Iterable<BbComment>>>(
title: Text("Issue: #$number"),
fetch: () async {
final auth = context.read<AuthModel>();
final items = await Future.wait([
auth.fetchBbJson('/repositories/$owner/$name/issues/$number'),
auth.fetchBbWithPage(
'/repositories/$owner/$name/issues/$number/comments')
final res = await Future.wait([
auth
.fetchBbJson('/repositories/$owner/$name/issues/$number')
.then((value) => BbIssues.fromJson(value)),
auth
.fetchBbWithPage(
'/repositories/$owner/$name/issues/$number/comments')
.then(
(value) => [for (var v in value.items) BbComment.fromJson(v)])
]);
return Tuple2(BbIssues.fromJson(items[0]),
[for (var v in items[1].data) BbComment.fromJson(v)]);
return Tuple2(res[0] as BbIssues, res[1] as Iterable<BbComment>);
},
actionBuilder: (data, _) => ActionEntry(
iconData: Octicons.plus,

View File

@ -29,13 +29,14 @@ class BbUserScreen extends StatelessWidget {
: 'User'),
fetch: () async {
final res = await Future.wait([
auth.fetchBbJson('/${isTeam ? 'teams' : 'users'}/$_accountId'),
auth.fetchBbWithPage('/repositories/$_login'),
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)]),
]);
return Tuple2(
BbUser.fromJson(res[0]),
[for (var v in res[1].data) BbRepo.fromJson(v)],
);
return Tuple2(res[0] as BbUser, res[1] as Iterable<BbRepo>);
},
action: isViewer
? ActionEntry(

View File

@ -264,7 +264,7 @@ class GhIssueScreen extends StatelessWidget {
return LongListPayload(
header: res,
totalCount: issue.timelineItems.totalCount,
cursor: issue.timelineItems.pageInfo.endCursor!,
cursor: issue.timelineItems.pageInfo.endCursor,
leadingItems: issue.timelineItems.nodes!.toList(),
trailingItems: [],
);
@ -274,7 +274,7 @@ class GhIssueScreen extends StatelessWidget {
return LongListPayload(
header: res,
totalCount: pr.timelineItems.totalCount,
cursor: pr.timelineItems.pageInfo.endCursor!,
cursor: pr.timelineItems.pageInfo.endCursor,
leadingItems: pr.timelineItems.nodes!.toList(),
trailingItems: [],
);
@ -288,7 +288,7 @@ class GhIssueScreen extends StatelessWidget {
return LongListPayload(
header: res,
totalCount: issue.timelineItems.totalCount,
cursor: issue.timelineItems.pageInfo.endCursor!,
cursor: issue.timelineItems.pageInfo.endCursor,
leadingItems: issue.timelineItems.nodes!.toList(),
);
} else {
@ -297,7 +297,7 @@ class GhIssueScreen extends StatelessWidget {
return LongListPayload(
header: res,
totalCount: pr.timelineItems.totalCount,
cursor: pr.timelineItems.pageInfo.endCursor!,
cursor: pr.timelineItems.pageInfo.endCursor,
leadingItems: pr.timelineItems.nodes!.toList(),
);
}

View File

@ -30,8 +30,10 @@ class GoUserScreen extends StatelessWidget {
limit: 6),
]);
return Tuple2(GogsUser.fromJson(res[0]),
[for (var repo in res[1].data) GogsRepository.fromJson(repo)]);
return Tuple2(GogsUser.fromJson(res[0]), [
for (var repo in (res[1] as DataWithPage).data)
GogsRepository.fromJson(repo)
]);
},
action: isViewer
? ActionEntry(