Is there any issue with Google Maps for Flutter? Since upgrading to flutter 3.0.0 & now 3.0.3 from 2.10.3 Google Maps causes the app to crash and this happens without any error log as to what the cause of the crash is. This only happen on the 'AddAddressScreen' which is where the map is used. It attempts to load the Map Interface and then crashes automatically without any further information as what the cause of the crash is.
I also tried capturing the crash using crashlytics by Google and i'm still unable to find what the cause of the crash is.
Prior to this upgrade, the app worked perfectly on flutter 2.10.3.
I need help if anyone knows a work around
Kindly Find below the code:
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
