brianegan / flutter_redux

A library that connects Widgets to a Redux Store
MIT License
1.65k stars 219 forks source link

Build warning with Flutter 3.0 #233

Closed hs029 closed 2 years ago

hs029 commented 2 years ago

../../../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.

brianegan commented 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.

tudor07 commented 2 years ago

@brianegan this issue still occurs on flutter_redux: 0.10.0 and Flutter 2.10.3

brianegan commented 2 years ago

@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

tudor07 commented 2 years ago

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.

brianegan commented 2 years ago

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.