Flutter Want to navigate to google maps - flutter

I have a set of locations. Starting point > Mid Point > Ending Point.
I want to create a button in which when the user presses the button it will redirect the user to the actual google maps direction and it should set the direction automatically on google maps.
how can I make it work?

use url_launcher package and set latitudeopen and longitude of origin and destination location, then open this url
https://maps.google.com/maps?saddr=currentLatitude,currentLongitude&daddr=destLatitude,destLongitude
Url example :
http://maps.google.com/maps?saddr=41.3999625,2.1958264&daddr=41.3942644,2.1885308
example:
import 'package:url_launcher/url_launcher.dart';
...
GestureDetector(
onTap: ()=> launch('http://maps.google.com/maps?saddr=41.3999625,2.1958264&daddr=41.3942644,2.1885308'),
child: Text('open map'),
)
...

Related

How to implement fly-to current location of mapbox in flutter

I have a floating action button on the map. When I click on this button, irrespective of my exploring on the map it should fly-to my current location.
I am able to show my current location on the map, and I have created a floating action button on the map to track back to my current location. I have stored the current location on my shared prefs. Now, I am looking for a Mapbox Fly-To feature to move back my current location.
Here is my pubspec.yaml file
Here is my code:
This is my Mapbox Map Screen.
I was also facing the same issue but fixed with the help of Geolocator flutter package which give you the current location details. Based on this details you can animate the map view to the position you have passed.
Please find the example below
onPressed: () async {
var position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
mapController.animateCamera(
CameraUpdate.newLatLng(
LatLng(
position.latitude,
position.longitude,
),
),
);
},

Flutter Web: Right click -> Browser Context Menu -> Open Link in New Tab

I have a basic website using GetX for navigation. I have inkwells with ontap functions which navigate to a new view. Right now, if you right click these buttons there is no "open link in new tab/window", "save link as" or "copy link address".
Is there any way to get this functionality for Flutter Web?
Edit:
Since Flutter version 2.10, you no longer need to switch to channel beta for this.
Maybe I'm answering this late, but this may help someone in the future.
At the moment of writing this it is possible to be done, it is bugged on the stable channel, but it works perfectly on channel beta.
Just switch to channel beta:
flutter channel beta
flutter upgrade
Then follow this instructions to add url_launcher dependency to your project and import this package wherever you want to use it:
import 'package:url_launcher/link.dart';
And finally wrap any widget with this:
Link(
uri: Uri.parse('www.google.com'),
builder: (context, function) {
return InkWell(
onTap: () => print('Do something'),
child: Text('Right clickable text')
);
});

Open Google Maps from Flutter with place selected

I am trying to open Google Maps with a place selected. Can the below url be used with dynamic data? The one that I am using selects the first place I searched for on Google Maps. What else do I need to change or is this the right way to open Google Maps from Flutter?
I am using Url Launcher:
import 'package:url_launcher/url_launcher.dart';
Code:
name = Uri.encodeComponent(name);
name = name.replaceAll('%20', '+');
String googleUrl =
'https://www.google.com/maps/place/$name/#$latitude,$longitude,3z/data=!4m8!1m2!2m1!1s$name!3m4!1s0x89c259ae9485299b:0x8b3fcf671f63ac6b!8m2!3d$latitude!4d$longitude';
print(googleUrl);
if (await canLaunch(googleUrl)) {
await launch(googleUrl);
} else {
throw 'Could not open the map.';
}
I noticed that each place has a place_id. Can that be used to target specific place?
--- Solution thanks to comment below ---
https://developers.google.com/maps/documentation/urls/get-started
I suggest reading this doc for Google Maps. You can define the center area with a lat/long and the place's name on the URL. This should center the place on the configured coordinates. The URL that you can use should be similar to:
comgooglemaps://?q=$name&center=$lat,$long

How to get a list of sound notifications?

I'm building an app where the users can choose the notification sounds inside the app.
The app would display a List of all notification sound that are inside the smartphone.
The Question:
How can I get a list of all notification sounds from the users phone, so the user can choose the preferable sound?
Is there any package in pub.dev or any way to do this (Android & iOS)?
Currently, it is not extensively available. But there is a work around, and that is:
Have a button
On press of that, open up your Sound and Vibration Settings.
Let the user choose from there itself
For that you can use app_settings package.
This is simple representation of how you can open up your location settings on press of a button
Widget build(BuildContext context) {
return Row(
children: <Widget>[
RaisedButton(
onPressed: AppSettings.openLocationSettings(), // here is the magic
child: Text('Open Location Settings'),
),
],
);
}
Consider this as an option. If you don't find anything, you can come back to it, and make use of it :)
First thing there is no plugins available which are fit into your requirement.
For iOS & Android, It is mandatory to keep sound file inside your project to play custom sound when notification received.
You need to get a list of the available sound file inside your project and load it to the widget.
Thanks.

Create a button to open another app in Flutter

I would like to create a simple app in Flutter that contains for example 3 button , the event onPressed in the button should open another external app , is that possible in Flutter and how should I proceed?
You can use Column/Row to create your buttons. And after that you can simply use a RaisedButton like this:
ElevatedButton(
onPressed: () {
// use android_intent package to open other app
final intent = AndroidIntent(package: "com.android.facebook", action: "action_view");
intent.launch();
},
child: Text("Open Facebook")
)
It's easy to do it in Android using android_intent_plus and for iOS you can do it natively, this will help you.
In my case action: "action_view" caused app selection dialog getting opened. We can open specific component using below.
You can try android_intent library for launching external app. Documentation has some sample codes.
You may use sample code below.
var map={"AuthParams":authParam};
var intent=AndroidIntent(package:"in.app",arguments: map,componentName: "in.app.ui.splash.SplashActivity",/*action: "action_view"*/);
await intent.launch();