CodeMinion / another_brother

Another Brother Flutter SDK
BSD 3-Clause "New" or "Revised" License
21 stars 19 forks source link

Error: This expression has type 'void' and can't be used. #60

Closed savs90 closed 1 year ago

savs90 commented 1 year ago

Hello everyone. First I want to say a big THANK YOU to @CodeMinion for this plugin and his work.

And now to the point: Today I had to remove the plugin temporarily in order to work in an emulator and when I returned it back I got the following message: ../../.pub-cache/hosted/pub.dev/another_brother-0.0.34/lib/printer_info.dart:3300:53: Error: This expression has type 'void' and can't be used. This was both for Android and iOS. After some investigating I saw that the problem comes from the row: FlutterBluePlus flutterBlue = FlutterBluePlus.instance; After checking Flutter blue plus plugin I saw that this would be fine until version 1.9.5. but sadly version 1.10.0 is making a breaking change without bumping the major version and the result is the error in question. In version 1.9.5 of FlutterBluePlus, we have the following line: static FlutterBluePlus get instance => _instance; That in 1.10.0 changes to @Deprecated('No longer needed, remove this from your code') static void get instance => null; And in the current versions of another_brother plugin in pubsec.yaml we use: flutter_blue_plus: ^1.1.3 and thus the problem.

Workaround for solving this problem is to add inside pubsec.yaml : 'dependency_overrides: flutter_blue_plus: 1.9.5'

Root solutions can be:

  1. Changing the version in pubsec.yaml dependency to flutter_blue_plus: 1.9.5
  2. Rewriting the parts connected with flutter_blue_plus with the new API and setting the pubsec.yaml dependency to flutter_blue_plus: ^1.10.0

Related issue: https://github.com/boskokg/flutter_blue_plus/issues/413

BR

CodeMinion commented 1 year ago

Hi @savs90 ,

Thanks for reaching out about this and the kind words.

In another_brother we use version 1.1.3 so it feels like you might have done a "pub upgrade" on your project at some point which bumped your version of flutter_blue_plus to 1.10.0. Does that sound correct?

savs90 commented 1 year ago

Hey @CodeMinion Correct me if I'm wrong, but every time you do a pub get and you have flutter_blue_plus: ^1.1.3 specified with ^ in front of the version means that you will fetch the last version that is larger or equal to 1.1.3 and smaller than 2.

From https://docs.flutter.dev/packages-and-plugins/using-packages: dependencies: url_launcher: ^5.4.0 # Good, any version >= 5.4.0 but < 6.0.0 image_picker: '5.4.3' # Not so good, only version 5.4.3 works.

CodeMinion commented 1 year ago

Thanks for confirming @savs90 ! Mainly wanted to get a clear view of the root cause.

I'll spend some time this coming weekend to see what it would take to migrate to 1.10.0 of flutter_blue_plus so others don't have to do any work arounds.

Thanks again for the heads up and all the details.

CodeMinion commented 1 year ago

Hi @savs90 ,

Thanks again for reporting this. We just released version 1.0.0 of another_brother which updates flutter_blue_plus to the latest version and the code using it to match the API changes.

Thanks again,