Skip to content

Commit e59810f

Browse files
Merge pull request #1143 from zino-hofmann/macros/flutter3
feat(graphql_flutter): support flutter 3.0 and 2.x
2 parents ba4e69b + 7f12438 commit e59810f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.github/workflows/graphql_flutter_build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ jobs:
1010
- uses: subosito/flutter-action@v1
1111
with:
1212
channel: 'stable'
13-
flutter-version: '2.10.5'
1413
- run: make dep
1514
- run: make ci_fmt_flutter

examples/starwars/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ dependencies:
1111
sdk: flutter
1212
graphql_flutter:
1313
path: ../../packages/graphql_flutter
14-
graphql:
15-
path: ../../packages/graphql
14+
graphql: ^5.1.2-beta.1
1615
universal_platform:
1716
^0.1.3
1817
# https://github.com/flutter/flutter/issues/36126#issuecomment-596215587

packages/graphql_flutter/lib/src/widgets/cache_provider.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ class _CacheProviderState extends State<CacheProvider>
2020
with WidgetsBindingObserver {
2121
GraphQLClient? client;
2222

23+
/// This allows a value of type T or T?
24+
/// to be treated as a value of type T?.
25+
///
26+
/// We use this so that APIs that have become
27+
/// non-nullable can still be used with `!` and `?`
28+
/// to support older versions of the API as well.
29+
T? _ambiguate<T>(T? value) => value;
30+
2331
@override
2432
void initState() {
2533
super.initState();
2634

27-
WidgetsBinding.instance!.addObserver(this);
35+
_ambiguate(WidgetsBinding.instance)!.addObserver(this);
2836
}
2937

3038
@override
@@ -42,7 +50,7 @@ class _CacheProviderState extends State<CacheProvider>
4250
void dispose() {
4351
super.dispose();
4452

45-
WidgetsBinding.instance!.removeObserver(this);
53+
_ambiguate(WidgetsBinding.instance)!.removeObserver(this);
4654
}
4755

4856
/*

0 commit comments

Comments
 (0)