I have done everything listed below in the google_maps_flutter package: https://pub.dev/packages/google_maps_flutter. Even added render type in my main file:
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
/// MapsDemo is the Main Application.
class MapsDemo extends StatefulWidget {
const MapsDemo({super.key});
@override
State<MapsDemo> createState() => _MapsDemoState();
}
class _MapsDemoState extends State<MapsDemo> {
final LatLng sourceLocation = const LatLng(37.422, -122.084);
late GoogleMapController _mapController;
@override
void dispose() {
_mapController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('GoogleMaps examples')),
body: SizedBox(
height: MediaQuery.of(context).size.height,
child: DefaultTabController(
length: 2,
child: Column(
children: [
const SizedBox(
height: 30,
),
const SizedBox(
height: 40,
child: TabBar(
labelColor: Colors.black,
tabs: [
Text(
"Posts",
),
Text(
"Maps",
),
],
),
),
const SizedBox(
height: 20,
),
Expanded(
child: TabBarView(
children: [
const Center(
child: Text(
"Posts Available",
),
),
GoogleMap(
mapType: MapType.normal,
initialCameraPosition: CameraPosition(
target: sourceLocation,
zoom: 14.5,
),
markers: <Marker>{
Marker(
markerId: const MarkerId('sourceLocation'),
position: sourceLocation,
infoWindow: const InfoWindow(
title: 'Your Location',
),
onTap: () {
// Handle marker tap event here, if needed
},
),
},
onMapCreated: (GoogleMapController controller) {
_mapController = controller;
},
),
],
),
),
],
),
),
),
);
}
}
void main() {
WidgetsFlutterBinding.ensureInitialized();
final GoogleMapsFlutterPlatform mapsImplementation =
GoogleMapsFlutterPlatform.instance;
if (mapsImplementation is GoogleMapsFlutterAndroid) {
mapsImplementation.useAndroidViewSurface = true;
mapsImplementation.initializeWithRenderer(AndroidMapRenderer.legacy);
}
runApp(const MaterialApp(home: MapsDemo()));
}
This are the logs that i get on app launch:
D/MapsInitializer( 1186): preferredRenderer: LEGACY
D/zzcb ( 1186): preferredRenderer: LEGACY
I/zzcb ( 1186): Making Creator dynamically
I/DynamiteModule( 1186): Considering local module com.google.android.gms.maps_legacy_dynamite:0 and remote module ]
I/DynamiteModule( 1186): Selected remote version of
V/DynamiteModule( 1186): Dynamite loader version >= 2, using loadModule2NoCrashUtils
W/ProtoDataStoreFlagStore( 1186): Unable to retrieve flag snapshot for com.google.android.gms.maps#com.example.test_project, using defaults.
When i navigate to the maps tab it logs out:
D/MapsInitializer( 1186): preferredRenderer: null
D/zzcb ( 1186): preferredRenderer: null
I/TetheringManager( 1186): registerTetheringEventCallback:com.example.test_project
E/le.test_projec( 1186): Invalid ID 0x00000000.
2
E/le.test_projec( 1186): Invalid ID 0x00000000.
When i do so repeatedly it crashes the app (move to another tab and back it crashes the app) and prints the same above logs everytime.