Flutter的谷歌Map有什么问题吗?由于从2.10.3升级到Flutter 3.0.0和现在的3.0.3,谷歌Map会导致应用程序崩溃,并且没有任何错误日志来说明崩溃的原因是什么。这只发生在使用Map的“AddAddAddressScreen”上。它尝试加载Map接口,然后自动崩溃,没有任何进一步的信息,因为崩溃的原因是什么。
我也试过使用谷歌的crashlytics来捕捉崩溃,但我仍然无法找到崩溃的原因。
在这次升级之前,该应用程序在Flutter 2.10.3上运行良好。
我需要帮助如果有人知道附近的工作
请在下面找到代码:
import 'package:google_maps_flutter/google_maps_flutter.dart';
class AddAddressScreen extends StatefulWidget {
const AddAddressScreen({Key? key}) : super(key: key);
@override
State<AddAddressScreen> createState() => _AddAddressScreenState();
}
class _AddAddressScreenState extends State<AddAddressScreen> {
TextEditingController _addressController = TextEditingController();
late bool _isLoggedIn;
CameraPosition _cameraPosition =
CameraPosition(target: LatLng(9.072264, 7.491302), zoom: 17);
late Position position;
LatLng _initialPosition = LatLng(9.072264, 7.491302);
bool locationLoaded = false;
@override
void initState() {
super.initState();
// _getUserCurrentPosition();
_isLoggedIn = Get.find<AuthController>().userIsLoggedIn();
if (_isLoggedIn && Get.find<UserController>().userModel == null) {
Get.find<UserController>().getUserInfo();
}
if (Get.find<LocationController>().addressList.isNotEmpty) {
double lat =
double.parse(Get.find<LocationController>().getAddress["latitude"]);
double lng =
double.parse(Get.find<LocationController>().getAddress["longitude"]);
//set saved user address to camera position
_cameraPosition = CameraPosition(target: LatLng(lat, lng), zoom: 17);
//set initial position to saved user address
_initialPosition = LatLng(lat, lng);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: TitleTextWidget(
titleText: 'Add Address', titleColor: AppStyles.appSecondaryColor),
leading: GestureDetector(
onTap: () {
Get.back();
},
child: const Icon(Icons.arrow_back_outlined,
color: AppStyles.appSecondaryColor),
),
backgroundColor: AppStyles.appPrimaryColor,
),
backgroundColor: Colors.white,
body: GetBuilder<LocationController>(builder: (locationController) {
return SingleChildScrollView(
child: Column(
children: [
Container(
height: SizeConfig.height140,
width: double.maxFinite,
margin: EdgeInsets.only(
left: SizeConfig.width5,
right: SizeConfig.width5,
top: SizeConfig.height5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(SizeConfig.radius5),
border: Border.all(
width: 2, color: AppStyles.appPrimaryColor)),
child: Stack(
children: [
GoogleMap(
initialCameraPosition: CameraPosition(
target: _initialPosition, zoom: 17))
],
)),
Padding(
padding: EdgeInsets.only(
left: SizeConfig.width20, top: SizeConfig.height20),
child: SizedBox(
height: SizeConfig.height50,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: locationController.addressTypeList.length,
itemBuilder: ((context, index) {
return InkWell(
onTap: () {
locationController.setAddressTypeIndex(index);
},
child: Container(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.width20,
vertical: SizeConfig.width20),
margin: EdgeInsets.only(right: SizeConfig.width10),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(SizeConfig.radius5),
color: Theme.of(context).cardColor,
boxShadow: [
BoxShadow(
color: Colors.grey.shade300,
spreadRadius: 1,
blurRadius: 5)
],
),
child: Icon(
index == 0
? Icons.home_filled
: index == 1
? Icons.work_outlined
: Icons.location_on_outlined,
color:
locationController.addressTypeIndex == index
? AppStyles.appPrimaryColor
: AppStyles.appSecondaryColor,
),
),
);
})),
),
),
SizedBox(height: SizeConfig.height20),
Padding(
padding: EdgeInsets.only(left: SizeConfig.width10),
child: TitleTextWidget(titleText: 'Service Address'),
),
SizedBox(height: SizeConfig.height20),
buildAddress(),
],
),
);
}),
);
}
}
pubspec.yaml
#Maps & Geolocator
google_maps_flutter: ^2.1.8
geolocator: ^8.2.0
geocoding: ^2.0.4
flutter_google_places: ^0.3.0
2条答案
按热度按时间uyto3xhc1#
请确保您像下面这样指定Google Maps API密钥:
jgovgodb2#
尝试以下代码: