Flutter and Whatsapp Group - flutter

I managed to send whatsapp messages from my app with
launchWhatsapp(String num) async {
String url;
if (Platform.isAndroid) {
url = "https://wa.me/$num/?text=${Uri.parse('test')}"; // new line
} else {
url =
"https://api.whatsapp.com/send?phone=$num=${Uri.parse('test')}"; // new line
}
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
but I need to send the same message to multiple numbers, so how can I achieve this?
I can't use a loop because in that case the user should anyway confirm manually one by one so it would become very annoying.
I was thinking about creating a whatsapp group, but apparently that's not possible from flutter. Or maybe that's not the correct solution.
Any idea?

Related

How do I prepend http/https to a user entered string in flutter textfield?

I'm using texteditingcontrollers and if a user enters stackoverflow.com I want it to be taken as https://stackoverflow.com, so I can open the link using url_launcher package. Can this be done in dart?
Something like this could be done using Dart language:
#override
Future<void> launchUrl({required String url}) async {
url = checkUrl(url);
try {
final bool shouldContinue = await canLaunch(url);
if (shouldContinue) {
await launch(url, forceSafariVC: false);
return;
}
throw Exception('Could not launch $url');
} catch (e) {}
}
String checkUrl(String url) {
if (url.startsWith('http')) return url;
return 'https://$url';
}
You may also take a look at string_validator. Instead of creating your validating method, you may use a package like this one.
If you have further questions, please don't hesitate to write in the comments.

Send sms directly from flutter app on click in adnroid and ios,

I m trying to send SMS directly from my flutter app but I m not finding good package, I try flutter SMS but its open SMS default app or I also try telephony its send SMS only to android
Try "**url_launcher**" flutter plugin, using this you can directly call and send sms from the app you built.
//you can use it using this method as reference
// this is for calling to a required number
Future _callContact(BuildContext context, String number) async {
final url = 'tel:$number';
if (await canLaunch(url)) {
await launch(url);
}
else {
const snackbar = SnackBar(content: Text('Can\'t make a call'));
Scaffold.of(context).showSnackBar(snackbar);
}
}
// this is for sms
Future _smsContact(BuildContext context, String number) async {
final url = 'sms:$number';
if (await canLaunch(url)) {
await launch(url);
} else {
const snackbar = SnackBar(content: Text('Can\'t make a call'));
Scaffold.of(context).showSnackBar(snackbar);
}
}

Message body disappear after hash symbol in flutter url_launcher when send a SMS

I'm using url_launcher in flutter to send SMS.
But there are hash symbols in my message body, and after hash symbols ,all message is disappear.
For example,
String uri= 'sms:$phoneNumber?body=123##456';
if (await canLaunch(uri)) {
await launch(uri);
} else {
if (await canLaunch(uri)) {
await launch(uri);
} else {
throw 'Could not launch $uri';
}
}
The number '456' is disappear on SMS.
How to solve the problem ?
Replace "#" with "%23"
String uri= 'sms:$phoneNumber?body=123%23%23456';

how to create a method that will call URL's From a list with flutter

I am working with google books in my flutter project.
im trying to create a method that that will call the diffrent books URL's that i have stored in a List and call the list back using a future builder.
The list look somthing like this:
List<String> toBeReadBooksList = ['https://www.googleapis.com/books/v1/volumes?q=1086782593+isbn'];
You can do it a way that similar to this:
final url = 'https://www.googleapis.com/books/v1/volumes?q=1086782593+isbn';
final response = await http.get(url)
if (response.statusCode == 200) {
// Here you need to parse data from response, you should replace it with your realization:
return Data.fromJson(jsonDecode(response.body));
} else {
throw Exception('Failed to load data from $url');
}
You can read more about how to work with requests and responses to/from the Network in Official Documentation.
Import url_launcher plugin import 'package:url_launcher/url_launcher.dart';
and in your pubspec.yaml dependecies url_launcher: ^5.7.10
add this and call it to open the selected url
_launchURL() async {
const url = toBeReadBooksList[0];//your list url
if (await canLaunch(url)) {
await launch(url);
}
else {
throw 'Could not launch $url';
}
}

How to launch other android apps using the flutter app

I have used the following method as specified in the documentation.
Future<void> launchUniversalLink(String url) async {
if (await canLaunch(url)) {
final bool nativeAppLaunchSuccess = await launch(url, forceSafariVC: false, universalLinksOnly: true);
print(nativeAppLaunchSuccess);
}else {
print('launch not successfull');
}
}
if I give URL = 'https://www.WhatsApp.com'
print(nativeAppLaunchSuccess); output ==> true
but still the app launches in the browser.
can anyone help me with this problem
Oh I'm sorry. This is my mistake.
Please use 'device_apps' flutter package and usage is below.
And here is a how to know app package name.
https://www.techmesto.com/find-android-app-package-name/
In ios, you know other app's custom Url schema that officially opened.
But usually we can not know that url.
So below ios code is executed, it will open appstore page and need to push 'open' button.
if (Platform.isAndroid) {
if (await DeviceApps.isAppInstalled('com.nbt.moves') ==
true) {
DeviceApps.openApp('com.nbt.moves');
}
} else {
const url =
'https://apps.apple.com/kr/app/%EC%BA%90%EC%8B%9C%EC%8A%AC%EB%9D%BC%EC%9D%B4%EB%93%9C-%EC%8A%A4%ED%85%9D%EC%97%85/id1400703652?uo=4';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}