build: upgrade provider
This commit is contained in:
parent
1269b66eb4
commit
15ccf72a27
|
@ -14,8 +14,8 @@ class BbCommitsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<BbCommit, String>> _query(BuildContext context,
|
||||
[String nextUrl]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchBbWithPage(nextUrl ?? '/repositories/$owner/$name/commits/$ref');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -9,8 +9,7 @@ import 'package:provider/provider.dart';
|
|||
class BbExploreScreen extends StatelessWidget {
|
||||
Future<ListPayload<BbRepo, String>> _query(BuildContext context,
|
||||
[String nextUrl]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.fetchBbWithPage(
|
||||
final res = await context.read<AuthModel>().fetchBbWithPage(
|
||||
nextUrl ?? '/repositories?role=member&sort=-updated_on');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -14,8 +14,8 @@ class BbIssuesScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<BbIssues, String>> _query(BuildContext context,
|
||||
[String nextUrl]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchBbWithPage(nextUrl ?? '/repositories/$owner/$name/issues');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -14,8 +14,8 @@ class BbPullsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<BbPulls, String>> _query(BuildContext context,
|
||||
[String nextUrl]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchBbWithPage(nextUrl ?? '/repositories/$owner/$name/pullrequests');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -24,7 +24,7 @@ class BbRepoScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold<Tuple2<BbRepo, String>>(
|
||||
title: AppBarTitle('Repository'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final r = await auth.fetchBbJson('/repositories/$owner/$name');
|
||||
final repo = BbRepo.fromJson(r);
|
||||
final res = await auth.fetchBb(
|
||||
|
|
|
@ -10,8 +10,9 @@ import 'package:timeago/timeago.dart' as timeago;
|
|||
class BbTeamsScreen extends StatelessWidget {
|
||||
Future<ListPayload<BbUser, String>> _query(BuildContext context,
|
||||
[String nextUrl]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.fetchBbWithPage(nextUrl ?? '/teams?role=member');
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchBbWithPage(nextUrl ?? '/teams?role=member');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
|
|
|
@ -22,7 +22,11 @@ class BbUserScreen extends StatelessWidget {
|
|||
final _accountId = auth.activeAccount.accountId;
|
||||
final _login = login ?? auth.activeAccount.login;
|
||||
return RefreshStatefulScaffold<Tuple2<BbUser, Iterable<BbRepo>>>(
|
||||
title: Text(isViewer ? 'Me' : isTeam ? 'Team' : 'User'),
|
||||
title: Text(isViewer
|
||||
? 'Me'
|
||||
: isTeam
|
||||
? 'Team'
|
||||
: 'User'),
|
||||
fetchData: () async {
|
||||
final res = await Future.wait([
|
||||
auth.fetchBbJson('/${isTeam ? 'teams' : 'users'}/$_accountId'),
|
||||
|
|
|
@ -15,7 +15,7 @@ class GhCommitsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GhCommitsCommit, String>> _query(BuildContext context,
|
||||
[String cursor]) async {
|
||||
final res = await Provider.of<AuthModel>(context).gqlClient.execute(
|
||||
final res = await context.read<AuthModel>().gqlClient.execute(
|
||||
GhCommitsQuery(
|
||||
variables: GhCommitsArguments(
|
||||
owner: owner,
|
||||
|
|
|
@ -19,11 +19,9 @@ class GhComparisonScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold(
|
||||
title: AppBarTitle('Files'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.ghClient.getJSON(
|
||||
'/repos/$owner/$name/compare/$before...$head',
|
||||
convert: (vs) => GithubComparisonItem.fromJson(vs),
|
||||
);
|
||||
final res = await context.read<AuthModel>().ghClient.getJSON(
|
||||
'/repos/$owner/$name/compare/$before...$head',
|
||||
convert: (vs) => GithubComparisonItem.fromJson(vs));
|
||||
return res.files;
|
||||
},
|
||||
actionBuilder: (v, _) {
|
||||
|
|
|
@ -14,11 +14,14 @@ class GhContributorsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GithubContributorItem, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.ghClient.getJSON<List, List<GithubContributorItem>>(
|
||||
'/repos/$owner/$name/contributors?page=$page',
|
||||
convert: (vs) => [for (var v in vs) GithubContributorItem.fromJson(v)],
|
||||
);
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.getJSON<List, List<GithubContributorItem>>(
|
||||
'/repos/$owner/$name/contributors?page=$page',
|
||||
convert: (vs) =>
|
||||
[for (var v in vs) GithubContributorItem.fromJson(v)],
|
||||
);
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
items: res,
|
||||
|
|
|
@ -16,11 +16,13 @@ class GhFilesScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GithubFilesItem, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.ghClient.getJSON<List, List<GithubFilesItem>>(
|
||||
'/repos/$owner/$name/pulls/$pullNumber/files?page=$page',
|
||||
convert: (vs) => [for (var v in vs) GithubFilesItem.fromJson(v)],
|
||||
);
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.getJSON<List, List<GithubFilesItem>>(
|
||||
'/repos/$owner/$name/pulls/$pullNumber/files?page=$page',
|
||||
convert: (vs) => [for (var v in vs) GithubFilesItem.fromJson(v)],
|
||||
);
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
items: res,
|
||||
|
|
|
@ -13,11 +13,13 @@ class GhGistsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GithubGistsItem, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.ghClient.getJSON<List, List<GithubGistsItem>>(
|
||||
'/users/$login/gists?page=$page',
|
||||
convert: (vs) => [for (var v in vs) GithubGistsItem.fromJson(v)],
|
||||
);
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.getJSON<List, List<GithubGistsItem>>(
|
||||
'/users/$login/gists?page=$page',
|
||||
convert: (vs) => [for (var v in vs) GithubGistsItem.fromJson(v)],
|
||||
);
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
items: res,
|
||||
|
|
|
@ -14,14 +14,12 @@ class GhGistsFilesScreen extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
return RefreshStatefulScaffold<GithubGistsItem>(
|
||||
title: AppBarTitle('Files'),
|
||||
fetchData: () async {
|
||||
final data = await auth.ghClient.getJSON(
|
||||
'/gists/$id',
|
||||
convert: (vs) => GithubGistsItem.fromJson(vs),
|
||||
);
|
||||
final data = await context.read<AuthModel>().ghClient.getJSON(
|
||||
'/gists/$id',
|
||||
convert: (vs) => GithubGistsItem.fromJson(vs));
|
||||
return data;
|
||||
},
|
||||
bodyBuilder: (payload, _) {
|
||||
|
|
|
@ -407,7 +407,7 @@ __typename
|
|||
}
|
||||
}
|
||||
|
||||
var data = await Provider.of<AuthModel>(context).query('''
|
||||
var data = await context.read<AuthModel>().query('''
|
||||
fragment CommentParts on Comment {
|
||||
id
|
||||
createdAt
|
||||
|
@ -467,7 +467,6 @@ fragment ReactableParts on Reactable {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
return LongListStatefulScaffold(
|
||||
title: Text(isPullRequest ? 'Pull Request' : 'Issue'),
|
||||
trailingBuilder: (payload, setState) {
|
||||
|
@ -479,14 +478,15 @@ fragment ReactableParts on Reactable {
|
|||
ActionItem(
|
||||
text: payload['closed'] ? 'Reopen issue' : 'Close issue',
|
||||
onTap: (_) async {
|
||||
final res = await auth.gqlClient.execute(
|
||||
GhOpenIssueQuery(
|
||||
variables: GhOpenIssueArguments(
|
||||
id: payload['id'],
|
||||
open: payload['closed'],
|
||||
),
|
||||
),
|
||||
);
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.gqlClient
|
||||
.execute(GhOpenIssueQuery(
|
||||
variables: GhOpenIssueArguments(
|
||||
id: payload['id'],
|
||||
open: payload['closed'],
|
||||
),
|
||||
));
|
||||
setState(() {
|
||||
payload['closed'] = res.data.reopenIssue?.issue?.closed ??
|
||||
res.data.closeIssue.issue.closed;
|
||||
|
|
|
@ -23,7 +23,6 @@ class _GhIssueFormScreenState extends State<GhIssueFormScreen> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
|
||||
return CommonScaffold(
|
||||
title: Text('Submit an issue'),
|
||||
|
@ -58,8 +57,10 @@ class _GhIssueFormScreenState extends State<GhIssueFormScreen> {
|
|||
child: Text('Submit'),
|
||||
onPressed: () async {
|
||||
final slug = RepositorySlug(widget.owner, widget.name);
|
||||
|
||||
final res = await auth.ghClient.issues
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.issues
|
||||
.create(slug, IssueRequest(title: _title, body: _body));
|
||||
await theme.push(
|
||||
context,
|
||||
|
|
|
@ -16,13 +16,12 @@ class GhIssuesScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GhIssuesIssue, String>> _query(BuildContext context,
|
||||
[String cursor]) async {
|
||||
final res =
|
||||
await Provider.of<AuthModel>(context).gqlClient.execute(GhIssuesQuery(
|
||||
variables: GhIssuesArguments(
|
||||
owner: owner,
|
||||
name: name,
|
||||
cursor: cursor,
|
||||
)));
|
||||
final res = await context.read<AuthModel>().gqlClient.execute(GhIssuesQuery(
|
||||
variables: GhIssuesArguments(
|
||||
owner: owner,
|
||||
name: name,
|
||||
cursor: cursor,
|
||||
)));
|
||||
final issues = res.data.repository.issues;
|
||||
return ListPayload(
|
||||
cursor: issues.pageInfo.endCursor,
|
||||
|
|
|
@ -21,18 +21,19 @@ class GhNewsScreenState extends State<GhNewsScreen> {
|
|||
Future.microtask(() async {
|
||||
// Check if there are unread notification items.
|
||||
// 1 item is enough since count is not displayed for now.
|
||||
var items = await Provider.of<AuthModel>(context)
|
||||
var items = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.getJSON('/notifications?per_page=1');
|
||||
|
||||
if (items is List && items.isNotEmpty) {
|
||||
Provider.of<NotificationModel>(context).setCount(1);
|
||||
context.read<NotificationModel>().setCount(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<ListPayload<GithubEvent, int>> fetchEvents([int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final login = auth.activeAccount.login;
|
||||
|
||||
final events = await auth.ghClient.getJSON(
|
||||
|
|
|
@ -21,13 +21,13 @@ class GhNotificationScreen extends StatefulWidget {
|
|||
|
||||
class GhNotificationScreenState extends State<GhNotificationScreen> {
|
||||
Future<Map<String, NotificationGroup>> fetchNotifications(int index) async {
|
||||
final ns = await Provider.of<AuthModel>(context).ghClient.getJSON(
|
||||
final ns = await context.read<AuthModel>().ghClient.getJSON(
|
||||
'/notifications?all=${index == 2}&participating=${index == 1}',
|
||||
convert: (vs) =>
|
||||
[for (var v in vs) GithubNotificationItem.fromJson(v)],
|
||||
);
|
||||
if (index == 0) {
|
||||
Provider.of<NotificationModel>(context).setCount(ns.length);
|
||||
context.read<NotificationModel>().setCount(ns.length);
|
||||
}
|
||||
|
||||
Map<String, NotificationGroup> _groupMap = {};
|
||||
|
@ -82,7 +82,7 @@ ${item.key}: pullRequest(number: ${item.subject.number}) {
|
|||
if (schema == '{}') return _groupMap;
|
||||
|
||||
// Fimber.d(schema);
|
||||
var data = await Provider.of<AuthModel>(context).query(schema);
|
||||
var data = await context.read<AuthModel>().query(schema);
|
||||
_groupMap.forEach((repo, group) {
|
||||
group.items.forEach((item) {
|
||||
var groupData = data[group.key];
|
||||
|
@ -121,9 +121,12 @@ ${item.key}: pullRequest(number: ${item.subject.number}) {
|
|||
),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
await auth.ghClient.activity.markRepositoryNotificationsRead(
|
||||
RepositorySlug.full(group.fullName));
|
||||
await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.activity
|
||||
.markRepositoryNotificationsRead(
|
||||
RepositorySlug.full(group.fullName));
|
||||
// await _onSwitchTab(); // TODO:
|
||||
},
|
||||
child: Icon(
|
||||
|
@ -171,10 +174,12 @@ ${item.key}: pullRequest(number: ${item.subject.number}) {
|
|||
actionBuilder: (_, refresh) => ActionEntry(
|
||||
iconData: Icons.done_all,
|
||||
onTap: () async {
|
||||
var value = await Provider.of<ThemeModel>(context)
|
||||
final value = await context
|
||||
.read<ThemeModel>()
|
||||
.showConfirm(context, Text('Mark all as read?'));
|
||||
if (value) {
|
||||
await Provider.of<AuthModel>(context)
|
||||
await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.activity
|
||||
.markNotificationsRead();
|
||||
|
|
|
@ -34,8 +34,10 @@ class GhObjectScreen extends StatelessWidget {
|
|||
}
|
||||
|
||||
final suffix = path == null ? '' : '/$path';
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.ghClient.repositories
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.repositories
|
||||
.getContents(RepositorySlug(owner, name), suffix, ref: ref);
|
||||
if (res.isDirectory) {
|
||||
res.tree.sort((a, b) {
|
||||
|
|
|
@ -18,11 +18,13 @@ class GhOrgReposScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<Repository, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final rs = await auth.ghClient.getJSON<List, List<Repository>>(
|
||||
'/orgs/$owner/repos?sort=updated&page=$page',
|
||||
convert: (vs) => [for (var v in vs) Repository.fromJson(v)],
|
||||
);
|
||||
final rs = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.getJSON<List, List<Repository>>(
|
||||
'/orgs/$owner/repos?sort=updated&page=$page',
|
||||
convert: (vs) => [for (var v in vs) Repository.fromJson(v)],
|
||||
);
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
items: rs,
|
||||
|
|
|
@ -14,13 +14,12 @@ class GhPullsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GhPullsPullRequest, String>> _query(BuildContext context,
|
||||
[String cursor]) async {
|
||||
final res =
|
||||
await Provider.of<AuthModel>(context).gqlClient.execute(GhPullsQuery(
|
||||
variables: GhPullsArguments(
|
||||
owner: owner,
|
||||
name: name,
|
||||
cursor: cursor,
|
||||
)));
|
||||
final res = await context.read<AuthModel>().gqlClient.execute(GhPullsQuery(
|
||||
variables: GhPullsArguments(
|
||||
owner: owner,
|
||||
name: name,
|
||||
cursor: cursor,
|
||||
)));
|
||||
final pulls = res.data.repository.pullRequests;
|
||||
return ListPayload(
|
||||
cursor: pulls.pageInfo.endCursor,
|
||||
|
|
|
@ -26,13 +26,12 @@ class GhRepoScreen extends StatelessWidget {
|
|||
GhRepoScreen(this.owner, this.name, {this.branch});
|
||||
|
||||
Future<GhRepoRepository> _query(BuildContext context) async {
|
||||
var res = await Provider.of<AuthModel>(context).gqlClient.execute(
|
||||
GhRepoQuery(
|
||||
variables: GhRepoArguments(
|
||||
owner: owner,
|
||||
name: name,
|
||||
branchSpecified: branch != null,
|
||||
branch: branch ?? '')));
|
||||
var res = await context.read<AuthModel>().gqlClient.execute(GhRepoQuery(
|
||||
variables: GhRepoArguments(
|
||||
owner: owner,
|
||||
name: name,
|
||||
branchSpecified: branch != null,
|
||||
branch: branch ?? '')));
|
||||
return res.data.repository;
|
||||
}
|
||||
|
||||
|
@ -50,17 +49,19 @@ class GhRepoScreen extends StatelessWidget {
|
|||
}
|
||||
|
||||
Future<String> _fetchContributors(BuildContext context) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.ghClient.getJSON(
|
||||
'/repos/$owner/$name/stats/contributors',
|
||||
);
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.getJSON('/repos/$owner/$name/stats/contributors');
|
||||
return res.length.toString();
|
||||
}
|
||||
|
||||
Future<String> _fetchReadme(BuildContext context) async {
|
||||
try {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.ghClient.repositories
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.repositories
|
||||
.getReadme(RepositorySlug(owner, name));
|
||||
return res.text;
|
||||
} catch (e) {
|
||||
|
@ -72,7 +73,6 @@ class GhRepoScreen extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
return RefreshStatefulScaffold<Tuple3<GhRepoRepository, String, String>>(
|
||||
title: AppBarTitle('Repository'),
|
||||
fetchData: () async {
|
||||
|
@ -136,15 +136,19 @@ class GhRepoScreen extends StatelessWidget {
|
|||
switch (v) {
|
||||
case GhRepoSubscriptionState.SUBSCRIBED:
|
||||
case GhRepoSubscriptionState.IGNORED:
|
||||
final res = await auth.ghClient.activity
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.activity
|
||||
.setRepositorySubscription(
|
||||
RepositorySlug(
|
||||
repo.owner.login, repo.name),
|
||||
subscribed: v ==
|
||||
GhRepoSubscriptionState.SUBSCRIBED,
|
||||
ignored:
|
||||
v == GhRepoSubscriptionState.IGNORED,
|
||||
);
|
||||
RepositorySlug(
|
||||
repo.owner.login, repo.name),
|
||||
subscribed: v ==
|
||||
GhRepoSubscriptionState
|
||||
.SUBSCRIBED,
|
||||
ignored: v ==
|
||||
GhRepoSubscriptionState.IGNORED,
|
||||
);
|
||||
setState(() {
|
||||
if (res.subscribed) {
|
||||
repo.viewerSubscription =
|
||||
|
@ -156,13 +160,16 @@ class GhRepoScreen extends StatelessWidget {
|
|||
});
|
||||
break;
|
||||
case GhRepoSubscriptionState.UNSUBSCRIBED:
|
||||
await auth.ghClient.activity
|
||||
await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.activity
|
||||
.deleteRepositorySubscription(
|
||||
RepositorySlug(
|
||||
repo.owner.login,
|
||||
repo.name,
|
||||
),
|
||||
);
|
||||
RepositorySlug(
|
||||
repo.owner.login,
|
||||
repo.name,
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
repo.viewerSubscription =
|
||||
GhRepoSubscriptionState.UNSUBSCRIBED;
|
||||
|
@ -181,11 +188,19 @@ class GhRepoScreen extends StatelessWidget {
|
|||
text: repo.viewerHasStarred ? 'Unstar' : 'Star',
|
||||
onPressed: () async {
|
||||
if (repo.viewerHasStarred) {
|
||||
await auth.ghClient.activity.unstar(
|
||||
RepositorySlug(repo.owner.login, repo.name));
|
||||
await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.activity
|
||||
.unstar(
|
||||
RepositorySlug(repo.owner.login, repo.name));
|
||||
} else {
|
||||
await auth.ghClient.activity.star(
|
||||
RepositorySlug(repo.owner.login, repo.name));
|
||||
await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.activity
|
||||
.star(
|
||||
RepositorySlug(repo.owner.login, repo.name));
|
||||
}
|
||||
setState(() {
|
||||
repo.viewerHasStarred = !repo.viewerHasStarred;
|
||||
|
|
|
@ -21,10 +21,10 @@ class GhReposScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GhReposRepository, String>> _query(BuildContext context,
|
||||
[String cursor]) async {
|
||||
final res = await Provider.of<AuthModel>(context).gqlClient.execute(
|
||||
GhReposQuery(
|
||||
variables:
|
||||
GhReposArguments(owner: owner, isStar: isStar, after: cursor)));
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth.gqlClient.execute(GhReposQuery(
|
||||
variables:
|
||||
GhReposArguments(owner: owner, isStar: isStar, after: cursor)));
|
||||
final data = res.data.user;
|
||||
if (isStar) {
|
||||
return ListPayload(
|
||||
|
|
|
@ -46,7 +46,8 @@ class _GhSearchScreenState extends State<GhSearchScreen> {
|
|||
_loading = true;
|
||||
});
|
||||
try {
|
||||
var data = await Provider.of<AuthModel>(context).query('''
|
||||
final auth = context.read<AuthModel>();
|
||||
final data = await auth.query('''
|
||||
{
|
||||
repository: search(first: $pageSize, type: REPOSITORY, query: "$keyword") {
|
||||
nodes {
|
||||
|
|
|
@ -14,7 +14,7 @@ class GhUserOrganizationScreen extends StatelessWidget {
|
|||
Future<ListPayload<GithubUserOrganizationItem, int>> _query(
|
||||
BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res =
|
||||
await auth.ghClient.getJSON<List, List<GithubUserOrganizationItem>>(
|
||||
'/users/$login/orgs?page=$page',
|
||||
|
|
|
@ -42,17 +42,17 @@ class GhUsersScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GhUsersUser, String>> _queryUsers(BuildContext context,
|
||||
[String cursor]) async {
|
||||
final res = await Provider.of<AuthModel>(context).gqlClient.execute(
|
||||
GhUsersQuery(
|
||||
variables: GhUsersArguments(
|
||||
login: login,
|
||||
repoName: repoName,
|
||||
isFollowers: type == UsersScreenType.follower,
|
||||
isFollowing: type == UsersScreenType.following,
|
||||
isStar: type == UsersScreenType.star,
|
||||
isWatch: type == UsersScreenType.watch,
|
||||
isMember: type == UsersScreenType.member,
|
||||
after: cursor)));
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth.gqlClient.execute(GhUsersQuery(
|
||||
variables: GhUsersArguments(
|
||||
login: login,
|
||||
repoName: repoName,
|
||||
isFollowers: type == UsersScreenType.follower,
|
||||
isFollowing: type == UsersScreenType.following,
|
||||
isStar: type == UsersScreenType.star,
|
||||
isWatch: type == UsersScreenType.watch,
|
||||
isMember: type == UsersScreenType.member,
|
||||
after: cursor)));
|
||||
|
||||
switch (type) {
|
||||
case UsersScreenType.follower:
|
||||
|
|
|
@ -19,7 +19,8 @@ class GlBlobScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold<GitlabBlob>(
|
||||
title: AppBarTitle(path ?? ''),
|
||||
fetchData: () async {
|
||||
final res = await Provider.of<AuthModel>(context).fetchGitlab(
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth.fetchGitlab(
|
||||
'/projects/$id/repository/files/${path.urlencode}?ref=$ref');
|
||||
return GitlabBlob.fromJson(res);
|
||||
},
|
||||
|
|
|
@ -17,7 +17,7 @@ class GlCommitScreen extends StatelessWidget {
|
|||
GlCommitScreen(this.id, {this.sha});
|
||||
|
||||
Future<List<GitlabDiff>> _query(BuildContext context, [int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth
|
||||
.fetchGitlabWithPage('/projects/$id/repository/commits/$sha/diff');
|
||||
return (res.data as List).map((v) => GitlabDiff.fromJson(v)).toList();
|
||||
|
|
|
@ -14,7 +14,7 @@ class GlCommitsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GitlabCommit, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth
|
||||
.fetchGitlabWithPage('/projects/$id/repository/commits?page=$page');
|
||||
return ListPayload(
|
||||
|
|
|
@ -10,7 +10,7 @@ import 'package:timeago/timeago.dart' as timeago;
|
|||
class GlExploreScreen extends StatelessWidget {
|
||||
Future<ListPayload<GitlabProject, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth
|
||||
.fetchGitlabWithPage('/projects?order_by=last_activity_at&page=$page');
|
||||
return ListPayload(
|
||||
|
|
|
@ -20,7 +20,7 @@ class GlGroupScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold<Tuple2<GitlabGroup, int>>(
|
||||
title: Text('Group'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await Future.wait([
|
||||
auth.fetchGitlab('/groups/$id'),
|
||||
auth.fetchGitlabWithPage('/groups/$id/members?per_page=1')
|
||||
|
|
|
@ -9,7 +9,7 @@ import 'package:provider/provider.dart';
|
|||
class GlGroupsScreenn extends StatelessWidget {
|
||||
Future<ListPayload<GitlabGroup, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth.fetchGitlabWithPage('/groups?page=$page');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -22,13 +22,11 @@ class GlIssueScreen extends StatelessWidget {
|
|||
title: Text('Issue #$iid'),
|
||||
fetchData: () async {
|
||||
final type = isMr ? 'merge_requests' : 'issues';
|
||||
final auth = context.read<AuthModel>();
|
||||
final items = await Future.wait([
|
||||
Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/projects/$projectId/$type/$iid'),
|
||||
Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/projects/$projectId/$type/$iid/notes?sort=asc'),
|
||||
Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/projects/$projectId/$type/$iid/award_emoji'),
|
||||
auth.fetchGitlab('/projects/$projectId/$type/$iid'),
|
||||
auth.fetchGitlab('/projects/$projectId/$type/$iid/notes?sort=asc'),
|
||||
auth.fetchGitlab('/projects/$projectId/$type/$iid/award_emoji'),
|
||||
]);
|
||||
return Tuple3(
|
||||
GitlabTodoTarget.fromJson(items[0]),
|
||||
|
|
|
@ -14,7 +14,7 @@ class GlIssuesScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GitlabIssue, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth
|
||||
.fetchGitlabWithPage('/projects/$id/issues?state=opened&page=$page');
|
||||
return ListPayload(
|
||||
|
|
|
@ -13,7 +13,7 @@ class GlMembersScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GitlabUser, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await auth.fetchGitlabWithPage('/$type/$id/members?page=$page');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -14,7 +14,7 @@ class GlMergeRequestsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GitlabIssue, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final res = await Provider.of<AuthModel>(context).fetchGitlabWithPage(
|
||||
final res = await context.read<AuthModel>().fetchGitlabWithPage(
|
||||
'/projects/$id/merge_requests?state=opened&page=$page');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -28,7 +28,7 @@ class GlProjectScreen extends StatelessWidget {
|
|||
int, String>>(
|
||||
title: AppBarTitle('Project'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await Future.wait([
|
||||
auth.fetchGitlab('/projects/$id?statistics=1'),
|
||||
auth.fetchGitlab('/projects/$id/languages'),
|
||||
|
|
|
@ -16,7 +16,7 @@ class GlProjectActivityScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GitlabEvent, int>> _query(BuildContext context,
|
||||
[int page]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final vs = await auth.fetchGitlab('/projects/$id/events');
|
||||
final events = (vs as List).map((v) => GitlabEvent.fromJson(v)).toList();
|
||||
return ListPayload(cursor: page, items: events, hasMore: false);
|
||||
|
|
|
@ -47,10 +47,11 @@ class _GlSearchScreenState extends State<GlSearchScreen> {
|
|||
_loading = true;
|
||||
});
|
||||
try {
|
||||
final projects = await Provider.of<AuthModel>(context)
|
||||
final auth = context.read<AuthModel>();
|
||||
final projects = await auth
|
||||
.fetchGitlabWithPage('/search?scope=projects&search=$keyword');
|
||||
final users = await Provider.of<AuthModel>(context)
|
||||
.fetchGitlabWithPage('/search?scope=users&search=$keyword');
|
||||
final users =
|
||||
await auth.fetchGitlabWithPage('/search?scope=users&search=$keyword');
|
||||
_projects = [for (var v in projects.data) GitlabProject.fromJson(v)];
|
||||
_users = [for (var v in users.data) GitlabUser.fromJson(v)];
|
||||
} finally {
|
||||
|
|
|
@ -13,9 +13,9 @@ class GlStarrersScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GitlabStarrer, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res =
|
||||
await auth.fetchGitlabWithPage('/projects/$id/starrers?page=$page');
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchGitlabWithPage('/projects/$id/starrers?page=$page');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
|
|
|
@ -64,7 +64,7 @@ class GlTodosScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold<Iterable<GitlabTodo>>(
|
||||
title: Text('Todos'),
|
||||
fetchData: () async {
|
||||
final vs = await Provider.of<AuthModel>(context).fetchGitlab('/todos');
|
||||
final vs = await context.read<AuthModel>().fetchGitlab('/todos');
|
||||
return (vs as List).map((v) => GitlabTodo.fromJson(v));
|
||||
},
|
||||
bodyBuilder: (data, _) {
|
||||
|
|
|
@ -21,7 +21,7 @@ class GlUserScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold<Tuple2<GitlabUser, Iterable<GitlabProject>>>(
|
||||
title: Text(isViewer ? 'Me' : 'User'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final _id = id ?? auth.activeAccount.gitlabId;
|
||||
final res = await Future.wait([
|
||||
auth.fetchGitlab('/users/$_id'),
|
||||
|
|
|
@ -14,8 +14,8 @@ class GtCommitsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GiteaCommit, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchGiteaWithPage('/repos/$owner/$name/commits?page=$page&limit=20');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -14,9 +14,8 @@ class GtIssuesScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GiteaIssue, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final type = isPr ? 'pulls' : 'issues';
|
||||
final res = await auth.fetchGiteaWithPage(
|
||||
final res = await context.read<AuthModel>().fetchGiteaWithPage(
|
||||
'/repos/$owner/$name/issues?state=open&page=$page&limit=20&type=$type');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
|
|
|
@ -21,7 +21,8 @@ class GtObjectScreen extends StatelessWidget {
|
|||
title: AppBarTitle(path ?? 'Files'),
|
||||
fetchData: () async {
|
||||
final suffix = path == null ? '' : '/$path';
|
||||
final res = await Provider.of<AuthModel>(context)
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchGitea('/repos/$owner/$name/contents$suffix');
|
||||
return res;
|
||||
},
|
||||
|
|
|
@ -19,7 +19,7 @@ class GtOrgScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold<Tuple2<GiteaOrg, List<GiteaRepository>>>(
|
||||
title: Text(login),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await Future.wait([
|
||||
auth.fetchGitea('/orgs/$login'),
|
||||
auth.fetchGitea('/orgs/$login/repos'),
|
||||
|
|
|
@ -10,8 +10,9 @@ class GtOrgsScreen extends StatelessWidget {
|
|||
// final String branch; // TODO:
|
||||
Future<ListPayload<GiteaOrg, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.fetchGiteaWithPage('/orgs?limit=20&page=$page');
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchGiteaWithPage('/orgs?limit=20&page=$page');
|
||||
// TODO: https://github.com/go-gitea/gitea/issues/10199
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
|
|
|
@ -23,7 +23,7 @@ class GtRepoScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold<Tuple2<GiteaRepository, String>>(
|
||||
title: AppBarTitle('Repository'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await Future.wait([
|
||||
auth.fetchGitea('/repos/$owner/$name'),
|
||||
auth.fetchGitea('/repos/$owner/$name/contents/README.md'),
|
||||
|
|
|
@ -21,7 +21,7 @@ class GtUserScreen extends StatelessWidget {
|
|||
return RefreshStatefulScaffold<Tuple2<GiteaUser, List<GiteaRepository>>>(
|
||||
title: Text(isViewer ? 'Me' : 'User'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final auth = context.read<AuthModel>();
|
||||
final res = await Future.wait([
|
||||
auth.fetchGitea(isViewer ? '/user' : '/users/$login'),
|
||||
auth.fetchGitea(isViewer ? '/user/repos' : '/users/$login/repos'),
|
||||
|
|
|
@ -127,8 +127,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||
}
|
||||
|
||||
void showError(err) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
theme.showConfirm(context, Text('Something bad happens: $err'));
|
||||
context
|
||||
.read<ThemeModel>()
|
||||
.showConfirm(context, Text('Something bad happens: $err'));
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -44,7 +44,7 @@ class Avatar extends StatelessWidget {
|
|||
return Link(
|
||||
child: widget,
|
||||
onTap: () {
|
||||
Provider.of<ThemeModel>(context).push(context, linkUrl);
|
||||
context.read<ThemeModel>().push(context, linkUrl);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class _GhEmojiActionState extends State<GhEmojiAction> {
|
|||
var operation = isRemove ? 'remove' : 'add';
|
||||
|
||||
try {
|
||||
await Provider.of<AuthModel>(context).query('''
|
||||
await context.read<AuthModel>().query('''
|
||||
mutation {
|
||||
${operation}Reaction(input: {subjectId: "$id", content: $emojiKey}) {
|
||||
clientMutationId
|
||||
|
@ -53,8 +53,7 @@ mutation {
|
|||
payload[emojiKey]['viewerHasReacted'] = !isRemove;
|
||||
});
|
||||
} catch (e) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
theme.showWarning(context, e);
|
||||
context.read<ThemeModel>().showWarning(context, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ class MarkdownView extends StatelessWidget {
|
|||
|
||||
return MarkdownBody(
|
||||
onTapLink: (url) {
|
||||
final theme = context.read<ThemeModel>();
|
||||
|
||||
if (basePaths != null &&
|
||||
!url.startsWith('https://') &&
|
||||
!url.startsWith('http://')) {
|
||||
|
@ -38,7 +40,7 @@ class MarkdownView extends StatelessWidget {
|
|||
var y = path.join(x, url);
|
||||
if (y.startsWith('/')) y = y.substring(1);
|
||||
|
||||
return Provider.of<ThemeModel>(context).push(context,
|
||||
return theme.push(context,
|
||||
'/${basePaths[0]}/${basePaths[1]}/${basePaths[2]}?path=${y.urlencode}');
|
||||
}
|
||||
|
||||
|
@ -48,22 +50,22 @@ class MarkdownView extends StatelessWidget {
|
|||
|
||||
m = matchPattern(url, '/{owner}/{name}/pull/{number}');
|
||||
if (m != null) {
|
||||
return Provider.of<ThemeModel>(context).push(context, url);
|
||||
return theme.push(context, url);
|
||||
}
|
||||
|
||||
m = matchPattern(url, '/{owner}/{name}/issues/{number}');
|
||||
if (m != null) {
|
||||
return Provider.of<ThemeModel>(context).push(context, url);
|
||||
return theme.push(context, url);
|
||||
}
|
||||
|
||||
m = matchPattern(url, '/{owner}/{name}');
|
||||
if (m != null) {
|
||||
return Provider.of<ThemeModel>(context).push(context, url);
|
||||
return theme.push(context, url);
|
||||
}
|
||||
|
||||
m = matchPattern(url, '/{login}');
|
||||
if (m != null) {
|
||||
return Provider.of<ThemeModel>(context).push(context, url);
|
||||
return theme.push(context, url);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,8 @@ class _NotificationItemState extends State<NotificationItem> {
|
|||
loading = true;
|
||||
});
|
||||
try {
|
||||
await Provider.of<AuthModel>(context)
|
||||
await context
|
||||
.read<AuthModel>()
|
||||
.ghClient
|
||||
.activity
|
||||
.markThreadRead(payload.id);
|
||||
|
|
|
@ -30,7 +30,7 @@ dependencies:
|
|||
flutter_svg: ^0.19.0
|
||||
launch_review: ^2.0.0
|
||||
timeago: ^2.0.18
|
||||
provider: ^3.2.0
|
||||
provider: ^4.3.2
|
||||
filesize: ^1.0.4
|
||||
tuple: ^1.0.2
|
||||
uri: ^0.11.3
|
||||
|
|
Loading…
Reference in New Issue