bluetooth_print icon indicating copy to clipboard operation
bluetooth_print copied to clipboard

Cannot run example app from pub.dev

Open BenShelbourne opened this issue 4 years ago • 3 comments

I am trying to run the example found here but when I run it I get the following error.

The following _CastError was thrown attaching to the render tree:
type '(MethodCall) => Null' is not a subtype of type '((MethodCall) => Future<dynamic>)?' in type cast

What is the fix for this?

BenShelbourne avatar Aug 15 '21 15:08 BenShelbourne

the same issue.

pubspec.yaml environment: sdk: ">=2.10.0 <3.0.0" works well

environment: sdk: ">=2.12.0 <3.0.0" will throw the exception below

════════ Exception caught by widgets library ═══════════════════════════════════
The following _CastError was thrown building Builder:
type '(MethodCall) => Null' is not a subtype of type '((MethodCall) => Future<dynamic>)?' in type cast

The relevant error-causing widget was
GestureDetector
lib\main.dart:29
When the exception was thrown, this was the stack
#0      new BluetoothPrint._
package:bluetooth_print/bluetooth_print.dart:26
#1      BluetoothPrint._instance
package:bluetooth_print/bluetooth_print.dart:29
#2      BluetoothPrint._instance (package:bluetooth_print/bluetooth_print.dart)
package:bluetooth_print/bluetooth_print.dart:1
#3      BluetoothPrint.instance
package:bluetooth_print/bluetooth_print.dart:31
#4      new _PrinterManagePageState
package:bubble_tea/…/printer/printer_manage_page.dart:44
...
════════════════════════════════════════════════════════════════════════════════

fxia86 avatar Aug 15 '21 16:08 fxia86

@thon-ju are there any plans to migrate to 2.12 ?

BenShelbourne avatar Aug 19 '21 06:08 BenShelbourne

I have to modify the constructor to fix it From

  BluetoothPrint._() {
    _channel.setMethodCallHandler((MethodCall call) {
      _methodStreamController.add(call);
      return;
    } as Future<dynamic> Function(MethodCall)?);
  }

To

  BluetoothPrint._() {
    _channel.setMethodCallHandler((MethodCall call) async {
      _methodStreamController.add(call);
    } as Future<dynamic> Function(MethodCall)?);
  }

environment: sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter bluetooth_print: ^3.0.1

tranthanhvu avatar Aug 19 '21 07:08 tranthanhvu