flutter_isolate icon indicating copy to clipboard operation
flutter_isolate copied to clipboard

Unhandled Exception: MissingPluginException when using location

Open mohpezeshki opened this issue 6 years ago • 7 comments

void isolate1(String arg) async  {
  while(true){
    await Future.delayed(Duration(seconds: 2));
    LocationData location = await new Location().getLocation();
    print(location.latitude.toString() + " " + location.longitude.toString());
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final isolate = await FlutterIsolate.spawn(isolate1, "hello");
  LocationData location = await new Location().getLocation();
  print(location.latitude.toString() + " " + location.longitude.toString());
  runApp(MyApp());
}

this is my code and when i ran it , give me an error

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method getLocation on channel lyokone/location)
E/flutter (10352): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
E/flutter (10352): <asynchronous suspension>
      Location.getLocation (package:location/location.dart:61:8)
     isolate1 (package:test_isolate/main.dart:14:50)
E/flutter (10352): <asynchronous suspension>
     FlutterIsolate._isolateInitialize.<anonymous closure>.<anonymous closure> (package:flutter_isolate/flutter_isolate.dart:126:23)
     _rootRunUnary (dart:async/zone.dart:1136:13)
     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:764:19)
    _StreamController._add (dart:async/stream_controller.dart:640:7)
  _StreamController.add (dart:async/stream_controller.dart:586:5)
    _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

mohpezeshki avatar Sep 30 '19 15:09 mohpezeshki

Your problem is with this

Please see here and here for why.

Also please use code formatting in your issue to make it readable

rmawatson avatar Oct 01 '19 00:10 rmawatson

but i can not run even your example because this Unhandled Exception: MissingPluginException error i use stable channel and flutter version v1.9.1+hotfix.2

mohpezeshki avatar Oct 01 '19 06:10 mohpezeshki

@rmawatson same error with my own custom channel, works fine in the main isolate.

VadimOsovsky avatar Oct 04 '19 15:10 VadimOsovsky

P.S. Native code doesn't even get called, tested on android

VadimOsovsky avatar Oct 04 '19 15:10 VadimOsovsky

without looking at it I'm not sure. You can try applying this PR https://github.com/rmawatson/flutter_isolate/pull/22

rmawatson avatar Oct 04 '19 17:10 rmawatson

@rmawatson applying the PR did not help to solve the issue, can you please check if custom platformChannel calls work with this lib?

VadimOsovsky avatar Oct 07 '19 08:10 VadimOsovsky

P.S. Native code doesn't even get called, tested on android

+1 native code does not get called

shakeeb1998 avatar Oct 27 '19 11:10 shakeeb1998