2

I am trying to launch the map application according to the user's choice. But the google map on my mobile is opened, Before the bottom sheet that contains the list of apps opens. I want to wait until the user chooses the app. How do I achieve this?

This is my code to open the map, If the tasktype is address the

GestureDetector(
            onTap: () async {
              try {
                launchUrl(
                  Uri.parse("geo:${address.lat},${address.lng}"),
                  mode: LaunchMode.externalApplication,
                );
              } finally {
                launchUrl(Uri.parse(
                    "google.navigation:q=${address.lat},${address.lng}&mode=d"));
              }
            },
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                CommonText(
                  text: kLanguageList!.value.googleMaps.obs,
                  size: 1,
                  textColor: kGreen,
                  boldText: false,
                  underline: TextDecoration.underline,
                ),
                Image.asset(
                  kGoogleMapLogo,
                  scale: 20,
                ),
              ],
            ),
          ),
Senthur Kumaran
  • 1,135
  • 1
  • 7
  • 18

1 Answers1

1

I forget to remove the finally in the code. I think the finally block executed always and doesn't care about the try block.

GestureDetector(
            onTap: () async {
              launchUrl(
                Uri.parse("geo:${address.lat},${address.lng}"),
                mode: LaunchMode.externalApplication,
              );
            },
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                CommonText(
                  text: kLanguageList!.value.googleMaps.obs,
                  size: 1,
                  textColor: kGreen,
                  boldText: false,
                  underline: TextDecoration.underline,
                ),
                Image.asset(
                  kGoogleMapLogo,
                  scale: 20,
                ),
              ],
            ),
          )

I just removed the finally and everything is working fine. or we can use catch(e) to display the errors or exceptions. I used the urllauncher for launching the google map.

Senthur Kumaran
  • 1,135
  • 1
  • 7
  • 18