flutter - Flutter - 处理“serviceExtension”自定义请求时出错:方法不可用:ext.flutter.inspector.setPubRootDirectories
问题描述
我试图在打开屏幕时获取当前的 GPS 位置,并将地图置于当前位置的中心。
如果我不使用这个显示 MapScreen,一切正常。
该应用程序返回这个 MapScreen,下面的代码就是它所拥有的一切:
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';
class MapScreen extends StatefulWidget {
const MapScreen({Key? key}) : super(key: key);
@override
_MapScreenState createState() => _MapScreenState();
}
class _MapScreenState extends State<MapScreen> {
// Maps
late GoogleMapController mapController;
final LatLng _center = const LatLng(45.521563, -122.677433);
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
// Location GPS
Location location = Location();
late bool _serviceEnabled;
late PermissionStatus _permissionGranted;
late LocationData _locationData;
Future<LatLng> getLoc() async {
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
return _center;
}
}
_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await location.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
return _center;
}
}
_locationData = await location.getLocation();
return LatLng(_locationData.latitude ?? _center.latitude,
_locationData.longitude ?? _center.latitude);
}
@override
void initState() {
super.initState();
getLoc();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder<LatLng>(
future: getLoc(),
builder: (BuildContext context, AsyncSnapshot<LatLng> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
print('itemNo in FutureBuilder: ${snapshot.data}');
return Text('Done');
} else {
return const Text('Loading...');
}
},
));
}
}
当我尝试在我的 iOS 模拟器上运行该应用程序时,构建失败并出现以下错误:
Error handling 'serviceExtension' custom request: method not available: ext.flutter.inspector.setPubRootDirectories
解决方案
推荐阅读
- kubernetes - Kubernetes中具有ClusterIP服务类型的外部IP地址有什么用
- docker - Docker 信任:无法将信任轮换到新的受信任根:无法使用当前受信任的证书验证数据
- java - BeanCreationException:由 ClassNotFoundException 引起的 NoClassDefFoundError 创建名称为“entityManagerFactory”的 bean 时出错
- reactjs - 是否有可能将状态/道具值从一个组件传递到另一个组件
- parsing - 如何使这个语法 LL(1)
- c# - 在 .NET Framework 和 .NET Core 之间自动传递和拉取 JSON 数据
- java - java.awt.AWTError: Can't connect to X11 window server using ':0' 作为 DISPLAY 变量的值
- google-analytics - Google Analytics(分析)中未显示 Ecom 跟踪
- python - 在 pandas 和 groupby 中查找连续三行的平均值
- oracle - 在 Oracle Apex 的登录页面中再添加一个参数