I’m only 2 weeks in to coding in Flutter and I’m creating an app that simply shows a list of restaurants along with their location. I’ve made the widgets as stateful and have fed data into my app through a local json file that I have stored in an assets directory I created in the root of the folder.
I’ve managed to finish almost everything. For the maps section, I’ve displayed the location with marker using Open street maps, but I want to make that display as a clickable button that opens google maps via the url launcher. I’ve done the code and everything, but unfortunately it does not open. Following is the block of code in question:
SizedBox(
width: 500,
height: 300,
child: InkWell(
onTap: () async {
final String googleMapsUrl =
"comgooglemaps://?center=$restaurantDataModel.latitude,$restaurantDataModel.longitude";
if (await canLaunchUrl(
googleMapsUrl as Uri)) {
await launchUrl(googleMapsUrl as Uri);
} else {
throw "Could not launch Url";
}
},
child: FlutterMap(
options: MapOptions(
initialCenter: LatLng(
restaurantDataModel.latitude,
restaurantDataModel.longitude),
initialZoom: 15,
interactionOptions:
InteractionOptions(
flags: ~InteractiveFlag
.doubleTapZoom),
),
children: [
openStreetMapTileLayer,
MarkerLayer(markers: [
Marker(
point: LatLng(
restaurantDataModel
.latitude,
restaurantDataModel
.longitude),
width: 60,
height: 60,
alignment:
Alignment.centerLeft,
child: Icon(
Icons.location_pin,
size: 40,
color: Colors.red))
]),
]))),
Appreciate all the help I can get. Thank you.