-
-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(example): depend on updated angel server, add paging example
- Loading branch information
Showing
5 changed files
with
135 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:graphql_flutter/graphql_flutter.dart'; | ||
|
||
class ForceRebroadcast extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Mutation( | ||
options: MutationOptions( | ||
document: r''' | ||
mutation Rebroadcast { | ||
} | ||
''', | ||
), | ||
builder: (runMutation, result) { | ||
return result.loading | ||
? RaisedButton( | ||
onPressed: null, | ||
child: const Center( | ||
child: CircularProgressIndicator(), | ||
), | ||
) | ||
: RaisedButton( | ||
onPressed: () { | ||
runMutation({}); | ||
}, | ||
child: Text('REBROADCAST'), | ||
); | ||
}, | ||
); | ||
} | ||
} |
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,86 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:graphql_flutter/graphql_flutter.dart'; | ||
import 'package:starwars_app/reviews/review_subscription.dart' | ||
show DisplayReviews; | ||
import './force_rebroadcast.dart'; | ||
|
||
class PagingReviews extends StatelessWidget { | ||
static const BottomNavigationBarItem navItem = BottomNavigationBarItem( | ||
icon: Icon(Icons.description), | ||
title: Text('Paging'), | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Query( | ||
options: QueryOptions( | ||
document: r''' | ||
query Reviews($page: Int!) { | ||
reviews(page: $page) { | ||
page | ||
reviews { | ||
id | ||
episode | ||
stars | ||
commentary | ||
} | ||
} | ||
} | ||
''', | ||
variables: {'page': 0}, | ||
), | ||
builder: ( | ||
QueryResult result, { | ||
BoolCallback refetch, | ||
FetchMore fetchMore, | ||
}) { | ||
if (result.loading && result.data == null) { | ||
return const Center( | ||
child: CircularProgressIndicator(), | ||
); | ||
} | ||
|
||
if (result.hasException) { | ||
return Text(result.exception.toString()); | ||
} | ||
|
||
final nextPage = result.data['reviews']['page'] + 1; | ||
|
||
return Column( | ||
children: <Widget>[ | ||
Expanded( | ||
child: DisplayReviews( | ||
reviews: result.data['reviews']['reviews'] | ||
.cast<Map<String, dynamic>>(), | ||
), | ||
), | ||
(result.loading) | ||
? Center( | ||
child: CircularProgressIndicator(), | ||
) | ||
: RaisedButton( | ||
onPressed: () { | ||
fetchMore( | ||
FetchMoreOptions( | ||
variables: {'page': nextPage}, | ||
updateQuery: (existing, newReviews) => ({ | ||
'reviews': { | ||
'page': newReviews['reviews']['page'], | ||
'reviews': [ | ||
...existing['reviews']['reviews'], | ||
...newReviews['reviews']['reviews'] | ||
], | ||
} | ||
}), | ||
), | ||
); | ||
}, | ||
child: Text('LOAD PAGE $nextPage'), | ||
), | ||
ForceRebroadcast(), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
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