Unhandled Exception: MissingPluginException when using location
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)
Your problem is with this
Please see here and here for why.
Also please use code formatting in your issue to make it readable
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
@rmawatson same error with my own custom channel, works fine in the main isolate.
P.S. Native code doesn't even get called, tested on android
without looking at it I'm not sure. You can try applying this PR https://github.com/rmawatson/flutter_isolate/pull/22
@rmawatson applying the PR did not help to solve the issue, can you please check if custom platformChannel calls work with this lib?
P.S. Native code doesn't even get called, tested on android
+1 native code does not get called