Issue
I was trying to print my emulated device's location but it just prints a bunch of stuff rather than the location of the device. I've checked and the device's location is turned on.
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
void main() {
runApp(LocationApp());
}
class LocationApp extends StatelessWidget {
void locationGet() async {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low);
print(position);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: RaisedButton(
onPressed: () {
locationGet();
},
child: Text('LOCATION'),
),
),
),
);
}
}
and this is what I'm getting as an error while the location of the device is turned on and I have even allowed the use of location when it prompted me
E/flutter ( 7183): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: The location service on the device is disabled.
E/flutter ( 7183): #0 MethodChannelGeolocator._handlePlatformException (package:geolocator_platform_interface/src/implementations/method_channel_geolocator.dart:173:9)
E/flutter ( 7183): #1 MethodChannelGeolocator.getPositionStream.<anonymous closure> (package:geolocator_platform_interface/src/implementations/method_channel_geolocator.dart:152:11)
E/flutter ( 7183): #2 _invokeErrorHandler (dart:async/async_error.dart:16:24)
E/flutter ( 7183): #3 _HandleErrorStream._handleError (dart:async/stream_pipe.dart:282:9)
E/flutter ( 7183): #4 _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:161:13)
E/flutter ( 7183): #5 _rootRunBinary (dart:async/zone.dart:1214:47)
E/flutter ( 7183): #6 _CustomZone.runBinary (dart:async/zone.dart:1107:19)
E/flutter ( 7183): #7 _CustomZone.runBinaryGuarded (dart:async/zone.dart:1013:7)
E/flutter ( 7183): #8 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:376:15)
E/flutter ( 7183): #9 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:394:16)
E/flutter ( 7183): #10 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:294:7)
E/flutter ( 7183): #11 _ForwardingStreamSubscription._addError (dart:async/stream_pipe.dart:132:11)
E/flutter ( 7183): #12 _ForwardingStream._handleError (dart:async/stream_pipe.dart:97:10)
E/flutter ( 7183): #13 _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:161:13)
E/flutter ( 7183): #14 _rootRunBinary (dart:async/zone.dart:1214:47)
E/flutter ( 7183): #15 _CustomZone.runBinary (dart:async/zone.dart:1107:19)
E/flutter ( 7183): #16 _CustomZone.runBinaryGuarded (dart:async/zone.dart:1013:7)
E/flutter ( 7183): #17 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:376:15)
E/flutter ( 7183): #18 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:394:16)
E/flutter ( 7183): #19 _DelayedError.perform (dart:async/stream_impl.dart:622:14)
E/flutter ( 7183): #20 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:730:11)
E/flutter ( 7183): #21 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7)
E/flutter ( 7183): #22 _rootRun (dart:async/zone.dart:1182:47)
E/flutter ( 7183): #23 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 7183): #24 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 7183): #25 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter ( 7183): #26 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 7183): #27 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 7183): #28 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 7183): #29 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter ( 7183): #30 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 7183): #31 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter ( 7183):
D/EGL_emulation( 7183): eglMakeCurrent: 0xd921a120: ver 2 0 (tinfo 0xd920f1e0)
Solution
The problem is that some of the android virtual device's in android studio have bugs, in this case it was the google pixel 3, no matter what you do it will not return its location, you can fix it by just using a different device, the Nexus 5x works fine.
Answered By - user8240155
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.