Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4: Cache overhaul, gql_link integration, and more #648

Merged
merged 128 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
2e491a7
feat: drop Link layer in favor of package:gql_link and package:gql_exec
klavs Feb 16, 2020
7499323
feat: move to DocumentNode-only documents
klavs Feb 16, 2020
d711647
Merge pull request #564 from klavs/drop-link
micimize May 9, 2020
d457ce7
Merge pull request #565 from klavs/drop-string-documents
micimize May 9, 2020
a469b3f
merge current beta, deleting apq link
micimize May 9, 2020
4fb205c
feat: documentNode -> document, dependency issues, reexport links fro…
micimize May 9, 2020
f54c6ae
fix: query test
micimize May 9, 2020
ddb1d6c
Merge remote-tracking branch 'upstream/beta' into modularization
micimize May 9, 2020
951b45d
borrow some links from gql
micimize May 9, 2020
2ed7d82
cleanup examples a bit
micimize May 9, 2020
4f7b424
about to revert Request extension api idea
micimize May 13, 2020
e9b5660
feat(graphql): complete caching overhaul
micimize May 14, 2020
f64a6c8
feat(graphql): use new cache correctly everywhere else
micimize May 14, 2020
61582b3
fix(examples): flutter bloc pubspec
micimize May 14, 2020
f8699ee
refactor: ~ s/InMemoryCache/GraphQLCache/g
micimize May 14, 2020
283326f
docs: store api
micimize May 14, 2020
c8000bb
docs, tests: new cache normalization first pass
micimize May 14, 2020
2776201
normalization tests pass
micimize May 14, 2020
3ac5e44
caching sufficiently tested
micimize May 14, 2020
d9452bc
feat: starting on gql links
micimize May 17, 2020
0d7ef7a
feat: more work on gql links
micimize May 19, 2020
2c3c66c
feat: HiveStore
micimize May 19, 2020
39bde3f
generalized adding typename
micimize May 19, 2020
500064a
updating examples
micimize May 19, 2020
673e1ba
example build struff
micimize May 19, 2020
1062912
refactor(graphql): simplify exceptions and make them gql_link based
micimize May 20, 2020
dcbe127
refactor(graphql): QueryResult loading -> isLoading, optimistic -> is…
micimize May 20, 2020
80309a1
refactor(graphql): QueryResult.loading() and optimistic({ data }) con…
micimize May 20, 2020
2b447a0
fix(graphql): keep deprecated QueryResult api and mark it as such
micimize May 20, 2020
8ab6840
refactor(graphql): recover NetworkException and handle unknown except…
micimize May 20, 2020
84cba43
feat: cache now flags itself for broadcasting
micimize May 21, 2020
814ccb3
feat: client.fetchMore utility for leveraging the fetch more logic re…
micimize May 21, 2020
ca12bfc
going to go back to mutable api after all
micimize May 23, 2020
94d8380
refactor(graphql): generalized MutableDataClass, reorg, delete graphq…
micimize May 23, 2020
6d0b045
feat(graphql): work on making subscriptions more of a first-class cit…
micimize May 23, 2020
a0e0d5c
feat(graphql_flutter): work on making subscriptions more of a first-c…
micimize May 23, 2020
82724f0
fix(examples): cleanup bloc example
micimize May 23, 2020
bba4a7a
fix(tests): update tests
micimize May 24, 2020
13df194
refactor(graphql): deprecating SCREAMING_CASE enums
micimize May 31, 2020
b9d214c
refactor(graphql): decided to make lifecycle refactor breaking becaus…
micimize May 31, 2020
1e893b5
feat(graphql): Robust ObservableQuery docs
micimize May 31, 2020
7514b93
fix(examples): starwars example works again
micimize Jun 1, 2020
36ee5a2
docs(graphql): add more docstrings and comments
micimize Jun 1, 2020
7e1edee
feat(graphql_flutter): add ResultAccumulator, fix Subscription
micimize Jun 1, 2020
bc32bdd
feat(examples): reorg graphql example so pub displays code
micimize Jun 1, 2020
3246394
refactor(graphql_flutter): rename result accumulator
micimize Jun 1, 2020
6ba687e
fix(graphql): default-yet-overrideable variable
micimize Jun 1, 2020
9a5fff1
fix(graphql): fix rebroadcasting by refactoring onData callbacks into…
micimize Jun 4, 2020
20d0176
feat(graphql): re-add documentNode asdeprecated
micimize Jun 5, 2020
38cfd9b
feat(docs): v4 changelog
micimize Jun 5, 2020
ba7b641
fix(graphql): dumb ?? documentNode bug
micimize Jun 6, 2020
ffd3294
fix(examples): ignore missing token
micimize Jun 6, 2020
6db4677
feat(graphql): HiveStore.open
micimize Jun 6, 2020
1118cc7
feat(graphql_flutter): initHiveForFlutter
micimize Jun 7, 2020
330d89c
packaging(graphql_flutter): hive and path dependencies
micimize Jun 7, 2020
645d462
fix(ci): loosen path version
micimize Jun 7, 2020
a13eee2
test(client): add test case for rebroadcast on mutation
parisholley Jun 11, 2020
75393c2
fix(client): mutation not firing observer callbacks
parisholley Jun 11, 2020
7b08fca
refactor(client): use idiomatic emitsInOrder for mutation "query stre…
micimize Jun 17, 2020
0752aa2
Merge pull request #669 from parisholley/mutation
micimize Jun 17, 2020
aba3ccc
Fixed issue#676
vemarav Jun 24, 2020
65fdcb2
Fix issue #676
vemarav Jun 24, 2020
376fb13
Update pubspec.yaml
vemarav Jun 24, 2020
5445066
Update pubspec.yaml
vemarav Jun 24, 2020
1c287ef
Update pubspec.yaml
vemarav Jun 24, 2020
87d6be7
Update pubspec.yaml
vemarav Jun 24, 2020
07b7409
Update pubspec.yaml
vemarav Jun 24, 2020
1275c10
Merge pull request #677 from brewhackers-technologies/modularization
micimize Jun 24, 2020
681f29b
packaging: release v4 alpha.1
micimize Jun 17, 2020
2a3e6a1
feat(tests): test subscriptions
micimize Jun 19, 2020
dd3e1b8
working on making hive store more accessible
micimize Jun 24, 2020
292b2a0
better hive api
micimize Jul 21, 2020
22db4f7
fix(examples): starwars example cache
micimize Jul 23, 2020
2d1a7f2
feat(graphql): HiveStore api improvements, fetchmore fixes
micimize Jul 23, 2020
2f874ec
feat(examples): starwars hivestore usage
micimize Jul 23, 2020
1f21927
docs(v4): direct cache access
micimize Jul 24, 2020
0b3fbd9
fix(graphql): simplified AuthLink
micimize Jul 24, 2020
0dbbe78
test deeplyMergeLeft
micimize Jul 25, 2020
01768c5
packaging(graphql): alpha.2
micimize Jul 25, 2020
76c8bf1
packaging(graphql_flutter): alpha.2
micimize Jul 25, 2020
2ba6c74
fix(graphql): don't close mutations after callbacks
micimize Jul 27, 2020
5b6e3d0
fix(examples): update ios files for graphql_flutter/example
micimize Jul 27, 2020
3d67b38
packaging: 4.0.0-alpha.3
micimize Jul 27, 2020
05fdd0c
Merge pull request #702 from micimize/fix_mutation_closing
micimize Jul 27, 2020
d1d95fd
can add a goal
micimize Aug 12, 2020
496d994
feat(graphql): update old websocket_link
micimize Sep 5, 2020
c2733ca
feat(graphql): multipart file support
micimize Sep 5, 2020
27bca46
chore(packaging): rxdart and uuid_enhanced for old websocket
micimize Sep 5, 2020
c3d7764
chore(changelog): update changelog
micimize Sep 5, 2020
803a2c6
packaging(graphql_flutter): 4.0.0-alpha.4
micimize Sep 5, 2020
4ceb800
fix(graphql): sanitize multipart files for cache
micimize Sep 12, 2020
db1cdf7
4.0.0-alpha.5 cache references for multipart files
micimize Sep 12, 2020
9c84cb1
fix(docs): typo in docstring, add todo to sanitizeVariables
micimize Sep 12, 2020
2067b46
docs: add info on the new link system to readme
micimize Sep 12, 2020
de66cff
graphql: fix subscription initial result from cache
micimize Sep 13, 2020
7192c16
packaging: 4.0.0-alpha.6 subscription fix
micimize Sep 13, 2020
04e7888
feat(graphql): add isMutation etc helpers to Options types
micimize Sep 17, 2020
1cf6478
refactor(client): clean up unused helpers, clarify shoudRebroadcast
micimize Sep 17, 2020
6fc5e7e
feat(client): expose store, cleanup
micimize Sep 17, 2020
1e93376
fix(client): only queries are refetch safe
micimize Sep 17, 2020
e45b240
feat(client): refetchSafeQueries, clarify rebroadcast calls in docs
micimize Sep 17, 2020
ba7134a
feat(client): cache proxy methods on cache, resetStore with optional …
micimize Sep 17, 2020
7a1a095
packaging: 4.0.0-alpha.7
micimize Sep 17, 2020
d37e81c
chore(ci): I think fixes coverage and lint
micimize Sep 24, 2020
fe02bb8
refactor(client): pollInterval is now a Duration
micimize Sep 24, 2020
3e4870c
test(client): restore old websocket client tests
micimize Sep 24, 2020
9db0b44
chore: re-merge changelog and templates
micimize Sep 24, 2020
0a7b2d1
clean changelog
micimize Sep 24, 2020
f9d1adb
docs: correct multipart example
micimize Sep 24, 2020
b5a79f7
examples: merge and update flutter_bloc changes
micimize Sep 24, 2020
ac4759a
examples: merge and update flutter_bloc changes
micimize Sep 24, 2020
a9eed21
test(client): more cache and store tests
micimize Sep 24, 2020
5e2172e
cleanup as we move towards beta
micimize Sep 25, 2020
8e57807
fix changelog mangle
micimize Sep 25, 2020
3e06854
docs: update graphql readme
micimize Sep 25, 2020
2f04058
refactor(client): Fragment and FragmentRequest for more normalized api
micimize Sep 25, 2020
00f4a97
docs: update docs, add more sections
micimize Sep 25, 2020
cc2df60
4.0.0-alpha.9
micimize Sep 25, 2020
e96363c
typos
micimize Sep 25, 2020
38b2fd2
hotfix: bool json encoding support
micimize Sep 26, 2020
43d8cc4
4.0.0-alpha.10
micimize Sep 26, 2020
98b8cf7
fix(client): gql_http_link==0.3.2 for custom toJsons closing #734
micimize Sep 26, 2020
715e6a4
hotpatch
micimize Sep 26, 2020
950b292
ref raw diagram
micimize Sep 27, 2020
b858a02
v4 flutter bloc sample update
vasilich6107 Sep 27, 2020
de114b8
Merge pull request #736 from artflutter/v4-flutter-bloc-example-update
micimize Oct 2, 2020
d0224c9
update doc refs
micimize Oct 2, 2020
79a8143
Merge branch 'beta' into modularization
micimize Oct 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ unlinked_spec.ds
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/.last_build_id
**/ios/Flutter/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
Expand Down
142 changes: 142 additions & 0 deletions changelog-v3-v4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Migrating from v3 – v4

v4 aims to solve a number of sore spots, particularly with caching, largely by leveraging libraries from the https://github.com/gql-dart ecosystem. There has also been a concerted effort to add more API docstrings to the codebase.

## Cache overhaul

- There is now only a single `GraphQLCache`, which leverages [normalize](https://pub.dev/packages/normalize),
Giving us a much more `apollo`ish api including `typePolicies`
- `LazyCacheMap` has been deleted
- `GraphQLCache` marks itself for rebroadcasting (should fix some related issues)
- **`Store`** is now a seperate concern:

```dart
/// Only necessary on flutter
void main() async {
await initHiveForFlutter();
runApp(MyApp());
}

GraphQLCache(
// The default store is the InMemoryStore, which does NOT persist to disk
store: await HiveStore.open(),
)
```

## We now use the [gql_link system](https://github.com/gql-dart/gql/tree/master/links/gql_link)

- Most links are re-exported from `graphql/client.dart`
- `QueryOptions`, `MutationOptions`, etc are turned into
[gql_exec](https://github.com/gql-dart/gql/tree/master/links/gql_exec) `Request`s
before being sent down the link chain.
- `documentNode` is deprecated in favor of `DocumentNode document` for consistency with `gql` libraries
- We won't leave alpha until we have [full backwards compatability](https://github.com/gql-dart/gql/issues/57)

```diff
final httpLink = HttpLink(
- uri: 'https://api.github.com/graphql',
+ 'https://api.github.com/graphql',
);

final authLink = AuthLink(
getToken: () async => 'Bearer $YOUR_PERSONAL_ACCESS_TOKEN',
);

var link = authLink.concat(httpLink);

if (ENABLE_WEBSOCKETS) {
final websocketLink = WebSocketLink(
- uri: 'ws://localhost:8080/ws/graphql'
+ 'ws://localhost:8080/ws/graphql'
);

- link = link.concat(websocketLink);
+ // split request based on type
+ link = Link.split(
+ (request) => request.isSubscription,
+ websocketLink,
+ link,
+ );
}
```

This makes all link development coordinated across the ecosystem, so that we can leverage existing links like [gql_dio_link](https://pub.dev/packages/gql_dio_link), and all link-based clients benefit from new link development

## `subscription` API overhaul

`Subscription`/`client.subscribe` API is in line with the rest of the API

```dart
final subscriptionDocument = gql(
r'''
subscription reviewAdded {
reviewAdded {
stars, commentary, episode
}
}
''',
);
// graphql/client.dart usage
subscription = client.subscribe(
SubscriptionOptions(
document: subscriptionDocument
),
);

// graphql_flutter/graphql_flutter.dart usage
Subscription(
options: SubscriptionOptions(
document: subscriptionDocument,
),
builder: (result) { /*...*/ },
);
```

## Minor changes

- As mentioned before, `documentNode: gql(...)` is now `document: gql(...)`.
- The exported `gql` utility adds `__typename` automatically.
\*\*If you define your own, make sure to include `AddTypenameVisitor`,
or else that your cache `dataIdFromObject` works without it

### Enums are normalized and idiomatic

```diff
- QueryResultSource.OptimisticResult
+ QueryResultSource.optimisticResult
- QueryResultSource.Cache
+ QueryResultSource.cache
// etc

- QueryLifecycle.UNEXECUTED
+ QueryLifecycle.unexecuted
- QueryLifecycle.SIDE_EFFECTS_PENDING
+ QueryLifecycle.sideEffectsPending
```

### `client.fetchMore` (experimental)

The `fetchMore` logic is now available for when one isn't using `watchQuery`:

```dart
/// Untested example code
class MyQuery {
QueryResult latestResult;
QueryOptions initialOptions;

FetchMoreOptions get _fetchMoreOptions {
// resolve the fetchMore params based on some data in lastestResult,
// like last item id or page number, and provide custom updateQuery logic
}

Future<QueryResult> fetchMore() async {
final result = await client.fetchMore(
_fetchMoreOptions,
options: options,
previousResult: latestResult,
);
_latestResult = result;
return result;
}
}
```
5 changes: 2 additions & 3 deletions examples/flutter_bloc/lib/blocs/repos/my_repos_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,12 @@ class MyGithubReposBloc extends Bloc<MyGithubReposEvent, MyGithubReposState> {
return;
}

var mutatedRepo =
extractRepositoryData(queryResults.data) as LazyCacheMap;
var mutatedRepo = extractRepositoryData(queryResults.data);

final notloadingRepo = Repo(
id: repo.id,
name: repo.name,
viewerHasStarred: mutatedRepo.data['viewerHasStarred'],
viewerHasStarred: mutatedRepo['viewerHasStarred'],
isLoading: false,
);

Expand Down
4 changes: 2 additions & 2 deletions examples/flutter_bloc/lib/extended_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class _ExtendedBlocState extends State<ExtendedBloc> {
}

String parseOperationException(OperationException error) {
if (error.clientException != null) {
final exception = error.clientException;
if (error.linkException != null) {
final exception = error.linkException;

if (exception is NetworkException) {
return 'Failed to connect to ${exception.uri}';
Expand Down
1 change: 0 additions & 1 deletion examples/flutter_bloc/lib/extended_bloc/graphql/bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:graphql/client.dart';
import 'package:meta/meta.dart';
import 'package:graphql/internal.dart';

import 'package:graphql_flutter_bloc_example/extended_bloc/graphql/event.dart';
import 'package:graphql_flutter_bloc_example/extended_bloc/graphql/state.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RepositoriesBloc extends GraphqlBloc<Map<String, dynamic>> {
client: client,
options: options ??
WatchQueryOptions(
documentNode: parseString(r'''
document: parseString(r'''
query ReadRepositories($nRepositories: Int!, $after: String) {
viewer {
repositories(first: $nRepositories, after: $after) {
Expand Down
8 changes: 2 additions & 6 deletions examples/flutter_bloc/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class MyApp extends StatelessWidget {
}

GraphQLClient _client() {
final HttpLink _httpLink = HttpLink(
uri: 'https://api.github.com/graphql',
);
final HttpLink _httpLink = HttpLink('https://api.github.com/graphql');

final AuthLink _authLink = AuthLink(
getToken: () => 'Bearer $YOUR_PERSONAL_ACCESS_TOKEN',
Expand All @@ -55,9 +53,7 @@ class MyApp extends StatelessWidget {
final Link _link = _authLink.concat(_httpLink);

return GraphQLClient(
cache: OptimisticCache(
dataIdFromObject: typenameDataIdFromObject,
),
cache: GraphQLCache(),
link: _link,
);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/flutter_bloc/lib/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GithubRepository {

Future<QueryResult> getRepositories(int numOfRepositories) async {
final WatchQueryOptions _options = WatchQueryOptions(
documentNode: parseString(queries.readRepositories),
document: parseString(queries.readRepositories),
variables: <String, dynamic>{
'nRepositories': numOfRepositories,
},
Expand All @@ -32,7 +32,7 @@ class GithubRepository {
repo.viewerHasStarred ? mutations.removeStar : mutations.addStar;

final MutationOptions _options = MutationOptions(
documentNode: parseString(document),
document: parseString(document),
variables: <String, String>{
'starrableId': repo.id,
},
Expand Down
4 changes: 1 addition & 3 deletions examples/flutter_bloc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ environment:
dependencies:
flutter:
sdk: flutter

graphql:
path: ../../packages/graphql
cupertino_icons: ^0.1.2
flutter_bloc: ^3.2.0
gql: 0.12.2
flutter_bloc: ^4.0.0
equatable: ^0.2.0

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_bloc/test/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void main() {
final results = QueryResult(
data: decodeGithubResponse['data'],
exception: null,
loading: false,
source: QueryResultSource.network,
);

when(
Expand Down
1 change: 0 additions & 1 deletion examples/starwars/.flutter-plugins-dependencies

This file was deleted.

3 changes: 0 additions & 3 deletions examples/starwars/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@
/* Begin XCBuildConfiguration section */
249021D3217E4FDB00AE95B9 /* Profile */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -387,7 +386,6 @@
};
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -441,7 +439,6 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down
16 changes: 4 additions & 12 deletions examples/starwars/lib/client_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,22 @@ String uuidFromObject(Object object) {
return null;
}

final OptimisticCache cache = OptimisticCache(
dataIdFromObject: uuidFromObject,
);

ValueNotifier<GraphQLClient> clientFor({
@required String uri,
String subscriptionUri,
}) {
Link link = HttpLink(uri: uri);
Link link = HttpLink(uri);
if (subscriptionUri != null) {
final WebSocketLink websocketLink = WebSocketLink(
url: subscriptionUri,
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: Duration(seconds: 30),
),
subscriptionUri,
);

link = link.concat(websocketLink);
link = Link.split((request) => request.isSubscription, websocketLink, link);
}

return ValueNotifier<GraphQLClient>(
GraphQLClient(
cache: cache,
cache: GraphQLCache(store: HiveStore()),
link: link,
),
);
Expand Down
4 changes: 2 additions & 2 deletions examples/starwars/lib/episode/hero_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HeroForEpisode extends StatelessWidget {
Widget build(BuildContext context) {
return Query(
options: QueryOptions(
documentNode: gql(r'''
document: gql(r'''
query HeroForEpisode($ep: Episode!) {
hero(episode: $ep) {
__typename
Expand Down Expand Up @@ -40,7 +40,7 @@ class HeroForEpisode extends StatelessWidget {
return Text(result.exception.toString());
}

if (result.loading) {
if (result.isLoading) {
return const Center(
child: CircularProgressIndicator(),
);
Expand Down
8 changes: 5 additions & 3 deletions examples/starwars/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:universal_platform/universal_platform.dart';

import './client_provider.dart';
Expand All @@ -20,7 +19,10 @@ String get host {
final graphqlEndpoint = 'http://$host:3000/graphql';
final subscriptionEndpoint = 'ws://$host:3000/subscriptions';

void main() => runApp(MyApp());
void main() async {
await initHiveForFlutter();
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Expand Down
27 changes: 27 additions & 0 deletions examples/starwars/lib/reviews/review.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:meta/meta.dart';
import 'package:flutter/material.dart';

import '../episode/episode.dart';

Expand Down Expand Up @@ -43,3 +44,29 @@ class Review {
}

const String Function(Object jsonObject) displayReview = getPrettyJSONString;

class DisplayReviews extends StatelessWidget {
const DisplayReviews({
Key key,
@required this.reviews,
}) : super(key: key);

final List<Map<String, dynamic>> reviews;

@override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.all(8.0),
children: reviews
.map(displayReview)
.map<Widget>((String s) => Card(
child: Container(
padding: const EdgeInsets.all(15.0),
//height: 150,
child: Text(s),
),
))
.toList(),
);
}
}
Loading