' null'可以将可以分配给type;位置的变量'
我想使用“ Geolocator”软件包从用户那里获取地理位置数据。逻辑是这样的,当我收到地理位置时,我将其发送给控制器以获取Google Maps,并在一段时间后根据接收到的坐标将地图传输。我写了一个函数,但会引发一个错误:
类型“ null”的值无法分配给类型的变量 '位置'。尝试更改变量的类型,或施放 右手类型为“位置”。
显示的错误
Future<void> _getCurrentPosition() async {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
.then((Position position) async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target: LatLng(position.latitude, position.longitude), zoom: 14)));
}).catchError((e) {
print(e);
});}
在此替换一部分函数后
Position? position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
.then((Position position) async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target: LatLng(position.latitude, position.longitude), zoom: 14)));
}).catchError((e) {
print(e);
});}
发生了另一件事,当我在物理设备上运行应用程序时,调试器显示此消息:在1 796ms中重新启动应用程序。 2022-05-01 23:39:05.165 Runner [2516/0x102610580] [LVL = 3] +[GMSX_CCTCLEARCUTUPLOADER crastififneclastory]多个cctclearcutuploader的实例。多个上载器正常运行,但由于锁定争夺而对电池性能产生不利影响。 [tcp] tcp_input [c4.1:3] flags = [r] seq = 611763406,ack = 0,win = 0 state =确定的rcv_nxt = 611763406,snd_una,snd_una = 1878468883连接4:接收失败通知连接4:接收到econnnernesete connectect econnnernesetetementect TLS握手 - 生成errsslclosednotify连接4:无法连接3:-9816,原因-1连接4:遇到错误(3:-9816)任务&lt; d01e9b91-bb3f-4674-ab74-ab74-ab74-ab74-5063e63e63636262617&gt;&gt;&lt;&lt;&lt; HTTP负载失败,0/0字节(错误代码:-1200 [3:-9816])2 [TCP] TCP_INPUT [C4.1:3] flags = [r] seq = 611763406,ack = 0,ack = 0,win = 0 =闭合RCV_NXT = 611763406,SND_UNA = 1878468883任务&lt; d01E9B91-BB3F-4674-AB74-AB74-5063E6362617&gt;。完成错误[-1200]错误域= nsurlorrordomain code = -1200“已经发生了SSL错误,无法与服务器进行安全连接。” userInfo = {nserrorfailingurlstringkey = https://client4.google.com/glm/mmap,nslocalizedRecoverySuggeSuggestion =您是否想连接到服务器? 3F-4674-AB74-5063E6362617&GT ;.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalUploadTask
是什么,这是什么重要的?多谢!
I want to get geolocation data from the user using the "geolocator" package. The logic is such that when I receive a geolocation, I send it to the controller for Google Maps and after some time the map transfers according to the received coordinates. I wrote a function, but it throws an error :
A value of type 'Null' can't be assigned to a variable of type
'Position'. Try changing the type of the variable, or casting the
right-hand type to 'Position'.
The error showing there
Future<void> _getCurrentPosition() async {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
.then((Position position) async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target: LatLng(position.latitude, position.longitude), zoom: 14)));
}).catchError((e) {
print(e);
});}
After replacing a part of function on this
Position? position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
.then((Position position) async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target: LatLng(position.latitude, position.longitude), zoom: 14)));
}).catchError((e) {
print(e);
});}
There comes another thing, when i run the app on physical device the debugger shows this messages:Restarted application in 1 796ms. 2022-05-01 23:39:05.165 Runner[2516/0x102610580] [lvl=3] +[GMSx_CCTClearcutUploader crashIfNecessary] Multiple instances of CCTClearcutUploader were instantiated. Multiple uploaders function correctly but have an adverse affect on battery performance due to lock contention. [tcp] tcp_input [C4.1:3] flags=[R] seq=611763406, ack=0, win=0 state=ESTABLISHED rcv_nxt=611763406, snd_una=1878468883 Connection 4: received failure notification Connection 4: received ECONNRESET with incomplete TLS handshake - generating errSSLClosedNoNotify Connection 4: failed to connect 3:-9816, reason -1 Connection 4: encountered error(3:-9816) Task <D01E9B91-BB3F-4674-AB74-5063E6362617>.<1> HTTP load failed, 0/0 bytes (error code: -1200 [3:-9816]) 2 [tcp] tcp_input [C4.1:3] flags=[R] seq=611763406, ack=0, win=0 state=CLOSED rcv_nxt=611763406, snd_una=1878468883 Task <D01E9B91-BB3F-4674-AB74-5063E6362617>.<1> finished with error [-1200] Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://clients4.google.com/glm/mmap, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <D01E9B91-BB3F-4674-AB74-5063E6362617>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalUploadTask <D01E9B91-BB3F-4674-AB74-5063E6362617>.<1>" ), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://clients4.google.com/glm/mmap, NSUnderlyingError=0x28150ca50 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9816, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9816, _NSURLErrorNWPathKey=satisfied (Path is satisfied), viable, interface: utun2, ipv4, dns, expensive}}, _kCFStreamErrorCodeKey=-9816} [tcp] tcp_input [C4.1:3] flags=[R] seq=611763406, ack=0, win=0 state=CLOSED rcv_nxt=611763406, snd_una=1878468883 -canOpenURL: failed for URL: "comgooglemaps://" - error: "This app is not allowed to query for scheme comgooglemaps" -canOpenURL: failed for URL: "googlechromes://" - error: "This app is not allowed to query for scheme googlechromes" Lost connection to device.
Whats is it and is this important? Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用
或
Replace your code with
or