The url_launcher package (https://pub.dev/packages/url_launcher) doesn't seem to work for Flutter for Web. The following code prints "test url1" but nothing happens afterwards.
How can I implement mailto: like functionality in Flutter for Web which causes the default email app to open with a prepopulated 'to:' email address?
FlatButton(
onPressed: _mailto, //() => {},
padding: EdgeInsets.all(3.0),
child: _contactBtn(viewportConstraints),
)
_mailto() async {
const url = 'mailto:support#email.com?subject=Product Inquiry&body=';
print("test url1");
if (await canLaunch(url)) {
print("test url2");
await launch(url);
} else {
print("test url3");
throw 'Could not launch $url';
}
}
After experimenting a little I found a way to make url_launcher work with web.
Don't use canLaunch(url). Instead, just use launch(url), but wrap it in try-catch block. This way you should be safe and the email link will work. For catch you can just copy the email to clipboard and notify the user about that with a snackbar or smth. Probably not the best solution, but a good one, till we get something better.
Here is the sample code, so that you see what I mean:
void _launchMailClient() async {
const mailUrl = 'mailto:$kEmail';
try {
await launch(mailUrl);
} catch (e) {
await Clipboard.setData(ClipboardData(text: '$kEmail'));
_emailCopiedToClipboard = true;
}
}
import 'package:mailto/mailto.dart';
// For Flutter applications, you'll most likely want to use
// the url_launcher package.
import 'package:url_launcher/url_launcher.dart';
// ...somewhere in your Flutter app...
launchMailto() async {
final mailtoLink = Mailto(
to: ['to#example.com'],
cc: ['cc1#example.com', 'cc2#example.com'],
subject: 'mailto example subject',
body: 'mailto example body',
);
// Convert the Mailto instance into a string.
// Use either Dart's string interpolation
// or the toString() method.
await launch('$mailtoLink');
}
Related
this is the function to send an WhatsApp message (or just launch the WhatsApp with the message)
in the Cipher.dart
void sendCodeByWhatsApp(
String phone,
String message,
) async {
String url() {
if (Platform.isAndroid) {
return "https://wa.me/$phone/?text=$message";
} else {
return "https://api.whatsapp.com/send?phone=$phone=$message";
}
}
if (await canLaunchUrl(Uri.parse(url()))) {
await launchUrl(Uri.parse(url()));
} else {
throw 'Could not launch ${url()}';
}
}
and here I use it:
ElevatedButton(
child: const Icon(Icons.whatsapp, color: Colors.white,),
onPressed: (){
Cipher().sendCodeByWhatsApp(encrypt.encrypt, phone.text);
},
),
when adding a number and message, just open a page with WhatsApp logo, tells me:
we couldn't find the page you were looking for
Refer to this to get how to use the link properly link
There may also be an error if the number includes the country code like
+1 0123456789
Will give an error. The phone should not include the country code.
after doing some search, finally found the solution:
same code above, but the URL should be like this:
"whatsapp://send?phone=$phone&text=${Uri.parse(message)}";
for android, and it is working like a charm...
Change the ? to & and it will open the WhatsApp page in the browser for you
"https://wa.me/$phone/&text=$message";
I have a Flutter Application. Currently I am trying to make an automated integration tests using Test Driver.
This is what I am trying to do.
Scenario:
- Click on Button
- Check if the Progress Dialog appeared
I was wondering if it is somehow possible to get the boolean value of the second step. I was trying to do methods like these:
Future<bool> loadingIndicatorVisible () async {
var a = _driver.waitFor(find.byType("ProgressDialogType.Normal"));
}
but I was not able to do this with mentioned method.
This progress dialog has text "Loading...", but I was not able to do this with find.text either.
Is there any way to do this correctly?
This is something what helped me... I hope that someone in the future will see it useful
isVisible(SerializableFinder finder, {duration = 1}) async {
try {
await _driver.waitFor(finder, timeout: Duration(seconds: duration));
return true;
} catch(exception) {
return false;
}
}
And I used finder which looked like this:
final loadingIndicator = find.text("Loading...");
And of course this is method which I was calling out:
Future<bool> loadingIndicatorVisible () async {
return await isVisible(loadingIndicator);
}
I want to transite to Instagram profile, when I am tapping on button. I use this library url_launcher. But there I can use only Web Browser for this. What will I do, in order to reach my goal?
To open Native and WebView Instagram:
Add to your iOS/Runner/Info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
...
<string>instagram</string>
</array>
Install url_launcher ( https://pub.dev/packages/url_launcher )
Import
import 'package:url_launcher/url_launcher.dart';
Create some method like this;
Inside Widget for example:
_launchInstagram() async {
const nativeUrl = "instagram://user?username=severinas_app";
const webUrl = "https://www.instagram.com/severinas_app/";
if (await canLaunch(nativeUrl)) {
await launch(nativeUrl);
} else if (await canLaunch(webUrl)) {
await launch(webUrl);
} else {
print("can't open Instagram");
}
}
Well, I don't know if it's too late, but this works for me using the url_launcher library (tested on android only):
var url = 'https://www.instagram.com/<INSTAGRAM_PROFILE>/';
if (await canLaunch(url)) {
await launch(
url,
universalLinksOnly: true,
);
} else {
throw 'There was a problem to open the url: $url';
}
2022 update:
_launchInstagram() async {
var nativeUrl = "instagram://user?username=balkan.exe";
var webUrl = "https://www.instagram.com/balkan.exe";
try {
await launchUrlString(nativeUrl, mode: LaunchMode.externalApplication);
} catch (e) {
print(e);
await launchUrlString(webUrl, mode: LaunchMode.platformDefault);
}
}
I am not sure if you can launch the profile activity, unless you know the name (which might change in the future). But, if you can try launching the app by using Intent plugin:
Try adding the Intent plugin:
https://pub.dev/packages/intent
Add intent in you in your pubspec.yaml file.
You can call the specific app with the package name (in this case Instagram).
Intent()
..setAction(Action.ACTION_SHOW_APP_INFO)
..putExtra(Extra.EXTRA_PACKAGE_NAME, "instagram package name")
..startActivity().catchError((e) => print(e));
You can also make use Android flutter plugin for Intent:
https://pub.dev/packages/android_intent
This will support for Android :
Use it by specifying action, category, data and extra arguments for the intent. It does not support returning the result of the launched activity
For IOS url_launcher plugin can be used for deep linking
You can create a platform channel and use the intent to achieve that or use social_share package.
Install url_launcher ( https://pub.dev/packages/url_launcher )
They now have a mode parameter, which you set to LaunchMode.externalApplication;
Call it with the regular https url, if they have the app installed it will open the app, otherwise it will open in Safari. Don't worry about doing an app link and a website url, the package and the OS handle it accordingly.
For example, here are my links in our About section of the app to our socials..
SettingsListTileModel(
// This can be any website's url that has a corresponding app, we us it with Twitter, Facebook, Instagram, and Youtube.
onTap: () => launchUrl(
Uri.parse('https://www.instagram.com/forwheel_app/'),
mode: LaunchMode.externalApplication,
),
title: Text(
'Instagram',
style: context.bodyLarge),
),
trailing: Icon(
FontAwesomeIcons.squareArrowUpRight,
),
),
i want little ask about sending email with flutter . I using https://pub.dev/packages/flutter_email_sender#-readme-tab- for sending email.
Sending Function
Future sendEmail(String subject,String body,List<String> recipients) async{
final Email email = Email(body: body,subject: subject,recipients: recipients);
String platformResponse;
try {
await FlutterEmailSender.send(email);
platformResponse='success';
} catch (e) {
platformResponse = e.toString();
}
print(platformResponse);
}
View.dart
Center(
child: RaisedButton(
onPressed: () => _sendMail(),
child: Text('send'),
),
)
void _sendMail() async {
return await api.sendEmail(widget.namaUpdate, widget.jurusanUpdate,['zefry.reynando#gmail.com']);
}
it's possible sending email automatic without open gmail app first ? (Like in codeigniter)
i trying using another package but always open gmail app first. or this how it works?
Thanks
You're not likely to find a package that sends email out without either configuration or a visible mail client. That app would not by approved by either Apple or Google, because it might be a source of SPAM.
Using url_launcher I can open phone to call a number.
var phone = "+123456789";
launch("tel://$phone");
How can I do the same for facebook messenger and whatsapp?
I found the solution.
To open whatsapp:
var whatsappUrl ="whatsapp://send?phone=$phone";
await canLaunch(whatsappUrl)? launch(whatsappUrl):print("open whatsapp app link or do a snackbar with notification that there is no whatsapp installed");
To open messenger or facebook:
First get shortened url
If your facebook profile is facebook.com/yourName
facebook url would be fb.me/yourName and messenger url would be m.me/yourName
then you do
launch("http://$messengerUrl");
Facebook website will automatically open the link in the app even though it goes trough URL browser. If there is no app installed, it will go to the app/play store
To open WhatsApp you can use this plugin: https://pub.dartlang.org/packages/flutter_launch
1. Add this to your package's pubspec.yaml file:
dependencies:
flutter_launch: "^0.3.0"
2. Install it
$ flutter packages get
3. Import it
import 'package:flutter_launch/flutter_launch.dart';
4. Example:
await FlutterLaunch.launchWhatsapp(phone: "5534992019999", message: "Hello");
Complete example: https://pub.dartlang.org/packages/flutter_launch#-installing-tab-
Import package url_launcher:
url_launcher: ^6.0.3
Import dependency:
import 'package:url_launcher/url_launcher.dart';
Put your url:
const _url = 'https://api.whatsapp.com/...';
Create your function:
void _launchURL() async => await canLaunch(_url)
? await launch(_url) : throw 'Not found $_url';
Use, por example in Button:
FloatingActionButton(
onPressed: _launchURL,
...
),
This works for me! :D
we can use the flutter package https://pub.dev/packages/url_launcher
For sending with number and text --->
whatsapp://send?phone=XXXXXXXXX&text=Hellothere!
For sending only text --->
https://api.whatsapp.com/send?text=Hellothere!
You can use Flutter URL lanucher plugin to launch whatsapp app. There you need to add conditions for android and iphone. You can read complete Flutter tutorial here.
for android
var whatsappURl_android = "whatsapp://send?phone="+whatsapp+"&text=hello";
for iphone
var whatappURL_ios ="https://wa.me/$whatsapp?text=${Uri.parse("hello")}";
first detect the phone OS version - android OR iOS
if(Platform.isIOS){
// for iOS phone only
if( await canLaunch(whatappURL_ios)){
await launch(whatappURL_ios, forceSafariVC: false);
}else{
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: new Text("whatsapp no installed")));
}
}else{
// android , web
if( await canLaunch(whatsappURl_android)){
await launch(whatsappURl_android);
}else{
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: new Text("whatsapp no installed")));
}
}
import 'package:url_launcher/url_launcher.dart';
void _contactViaWhatsApp(context) async {
String whatsAppUrl = "";
String phoneNumber = 'your-phone-number';
String description = "your-custom-message";
if (Platform.isIOS) {
whatsAppUrl =
'whatsapp://wa.me/$phoneNumber/?text=${Uri.parse(description)}';
} else {
whatsAppUrl =
'https://wa.me/+$phoneNumber?text=${Uri.parse(description)}';
}
if (await canLaunch(whatsAppUrl)) {
await launch(whatsAppUrl);
} else {
final snackBar = SnackBar(
content: Text("Install WhatsApp First Please"),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}