Closed hs029 closed 2 years ago
There's already a beta version out which solves this problem , a new version 0.10.0
will also provide a new stable version with this functionality.
@brianegan this issue still occurs on flutter_redux: 0.10.0
and Flutter 2.10.3
@tudor07 Thanks for the report. Is it the exact same error message, or is it complaining that WidgetsBinding.instance must be nullable? Version 0.10.0 was built to support Flutter 3+ and may not work with older versions.
If it's the same message, please look at the code for your local version of flutter_redux 0.10.0 and see if the ?
still exist on line 474 & 576. If it does not, then something odd is happening and I may need to publish a new version.
The local code should be in ~/.pub-cache/hosted/pub.dartlang.org/flutter_redux-0.10.0
.
The two lines that contain Widgetbindings.instance
should look like:
https://github.com/brianegan/flutter_redux/blob/master/lib/flutter_redux.dart#L474 https://github.com/brianegan/flutter_redux/blob/master/lib/flutter_redux.dart#L576
The code is exactly like the one you provided.
The full error message:
../../../../dev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_redux-0.10.0/lib/flutter_redux.dart:474:31: Error: Method 'addPostFrameCallback'
cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../../dev/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((_) {
^^^^^^^^^^^^^^^^^^^^
../../../../dev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_redux-0.10.0/lib/flutter_redux.dart:576:31: Error: Method 'addPostFrameCallback'
cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../../dev/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((_) {
^^^^^^^^^^^^^^^^^^^^
Looks like the library is no longer compatible with Flutter 2 😔 It would be nice to fix this and still being able to use it for folks who didn't upgrade to Flutter 3 yet. If that is not possible maybe it's worth adding a warning in the docs.
It's not quite the same -- if you read, it's actually the opposite haha.
In the reported issue above, the error is:
Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
In your report, the error is:
Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
I hope you can understand, but as Flutter updates, so must this library. In this case, Flutter has made a breaking change, this library has adapted to support that change.
If you need to support Flutter 2, the previous versions should work, but sadly I do not have time to backport bug fixes. I'll add a note in the README.
../../../appdev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_redux-0.9.0/lib/flutter_redux.dart:474:22: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.