Skip to content

Commit ee25cfd

Browse files
feat(graphql_flutter): support flutter 3.0 and 2.x
Suggested-by: @fabis94 Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent ba4e69b commit ee25cfd

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
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

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)