How to send a message directly from my Flutter web application to WhatsApp Business? - flutter

I am building an flutter web application that has to be able to send message on specific WhatsApp Business number and WhatsApp number. What exactly am I supposed to do? If the user's device has either WhatsApp or WhatsApp Business, he opens it. But my problem is that if user's device has both WhatsApp and WhatsApp business, I want one to open on one condition.
var whatsappURlAndroid = "https://wa.me/$whatsappNumber/?text=Hi";
var whatappURLIos ="https://wa.me/$whatsappNumber?text=${Uri.parse("hello")}";
var webWhatsapp= "https://web.whatsapp.com/send?phone=$whatsappNumber&text=Hello";
if (defaultTargetPlatform == TargetPlatform.iOS) {
await launch(whatappURLIos, forceSafariVC: false);
}else if(defaultTargetPlatform == TargetPlatform.android){
await launch(whatsappURlAndroid);
}
else{
await launch(webWhatsapp);
}

FocusManager.instance.primaryFocus?.unfocus();
var whatsappUrl = "whatsapp://send?phone=${_countryCodeController.text +
_phoneController.text}" +
"&text=${Uri.encodeComponent(_messageController.text)}";
try {
launch(whatsappUrl);
} catch (e) {
// To handle error and display error message:
Helper.errorSnackBar(
context: context, message: "Unable to open whatsapp");
}

Related

How to send what'sapp message to any number from flutter?

I am using an api to get users data and i want to send messages to every users what's app number on click in flutter app. How to do this ?
https://www.youtube.com/watch?v=-wW2ZoDuFO4&t=391s
if windwos platform u can see my video
Use the plugin.
https://pub.dev/packages/url_launcher
final url = "https://wa.me/91XXXXXXXXXX?text=Hello";
//do not forgot to enter your country code instead of 91 and instead of XXXXXXXXXX enter phone number.
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url));
} else {
showSnackBar(message: "Can't share link", title: "Error");
}
if (!await launchUrl(Uri.parse(url))) throw 'Could not launch $url';

How to send message to multiple number in WhatsApp in one time?

I'm trying to send a message to multiple phone numbers via WhatsApp using Flutter:
sendMessage() async {
var number = ["201020402642", "201030666895"];
var baseUrl = "https://api.whatsapp.com/send/";
var urlIos = "";
number.forEach((element) async {
var url = baseUrl +"?phone=${element} &text=msg";
if (await canLaunch(url)) {
await launch(url);
} else {
print("not installed");
}
});
}
It only sends a message to the last number.
Is there a way to send a message to a group of numbers?
Unfortunately, there's no way to send a message for more than 1 number at the same time using deep links. The only way you can do something like this is by using the WhatsApp business API through REST requests. There are some third-party software with this feature like https://www.twilio.com/whatsapp
Here is the WhatsApp API doc
https://developers.facebook.com/docs/whatsapp/api/messages/#sending-messages

Connectivity plugin "getWifiName()" method to get ssid returns null in flutter for ios 13+

I am trying to get wifi ssid in flutter for ios(13+) with connectivity plugin but result returns null. I have added access wireless information from Xcode but still not working. Can anyone help out please?
Future<void> _updateConnectionStatus(ConnectivityResult result) async{
switch(result){
case ConnectivityResult.wifi:
String wifiName;
try {
if (Platform.isIOS) {
LocationAuthorizationStatus status =
await _connectivity.getLocationServiceAuthorization();
if (status == LocationAuthorizationStatus.notDetermined) {
print('wifiName notDetermined: ');
status = await _connectivity.requestLocationServiceAuthorization();
}
if (status == LocationAuthorizationStatus.authorizedAlways ||
status == LocationAuthorizationStatus.authorizedWhenInUse) {
print('wifiName authorizedWhenInUse: ');
wifiName = await _connectivity.getWifiName();
setState(() {
_ssid = wifiName != null ? wifiName : _ssid;
});
} else {
print('wifiName ,.,.,.,: ');
wifiName = await _connectivity.getWifiName();
}
} else {
LocationAuthorizationStatus status =
await _connectivity.getLocationServiceAuthorization();
// if(status == )
wifiName = await _connectivity.getWifiName();
print('android wifi');
print(wifiName);
}
} on PlatformException catch (e) {
print(e.toString());
wifiName = "Failed to get Wifi Name";
}
setState(() {
_connectionStatus ='result '+ '$result\n'
'Wifi Name: $wifiName\n';
print('_connectionStatus $_connectionStatus');
});
break;
case ConnectivityResult.mobile:
Fluttertoast.showToast(msg: 'Connected to mobile network');
break;
case ConnectivityResult.none:
Fluttertoast.showToast(msg: 'Connected to no network');
setState(() => _connectionStatus = result.toString());
break;
default:
setState(() => _connectionStatus = 'Failed to get connectivity.');
break;
}
}
I have tried with above code from connectivity plugin example. Also there is showing 'As of iOS 13, Apple announced that these APIs will no longer return valid information'. So how to achieve my goal?
In 2020, the flutter team decided to create a new plugin for wifi information, removing these methods from the connectivity plugin.
So check the network_info_plus plugin: the method signatures are just the same.
As on being able to access this on iOS 13+, according to the package's readme:
The CNCopyCurrentNetworkInfo will work for Apps that:
The app uses Core Location, and has the user’s authorization to use
location information.
The app uses the NEHotspotConfiguration API to configure the current
Wi-Fi network.
The app has active VPN configurations installed.
If your app falls into the last two categories, it will work as it is.
If your app doesn't fall into the last two categories, and you still
need to access the wifi information, you should request user's
authorization to use location information.
There is a helper method provided in this plugin to request the
location authorization: requestLocationServiceAuthorization. To
request location authorization, make sure to add the following keys to
your Info.plist file, located in /ios/Runner/Info.plist:
NSLocationAlwaysAndWhenInUseUsageDescription - describe why the app
needs access to the user’s location information all the time
(foreground and background). This is called Privacy - Location Always
and When In Use Usage Description in the visual editor.
NSLocationWhenInUseUsageDescription - describe why the app needs
access to the user’s location information when the app is running in
the foreground. This is called Privacy - Location When In Use Usage
Description in the visual editor.
So basically, from iOS13 on, you have to request the user's permission for location - it actually makes sense.

Accepting payments in Flutter Web

I am creating an application in Flutter Web that needs to collect payment information to create subscription charges. My plan was to use Stripe to do this, however, after making all the necessary methods for Stripe, I found that Stripe only accepts card data through Stripe Elements. Upon further research, I saw that essentially all payment platforms do this to maintain PCI compliance.
Is there any method of embedding Stripe elements(or any equivalent) into my application or is there an easier method of accepting payments with Flutter Web?
There's an unofficial Flutter Stripe package that might be what you're after: https://pub.dev/packages/stripe_payment
There's a new package called stripe_sdk, that appears to have Web support. I haven't tried it yet, but it says Web support in the description and has a web demo aswell :)
Also the old packages for mobile won't work for web, because they rely on WebView, which is not supported (and wouldn't make much sense) on web.
In case you're using Firebase as a backend, there's a stripe payments extension you can install in Firebase which makes it easy. How it works is you add a checkout_session in to a user collection and keep listening on the document. Stripe extension will update the document with a unique payments url and we just open that URL in a new tab to make the payment in the tab. We're using it in our web app, and it's working.
Something like :
buyProduct(Product pd) async {
setState(() {
loadingPayment = true;
});
String userUid = FirebaseAuth.instance.currentUser!.uid;
var docRef = await FirebaseFirestore.instance
.collection('users')
.doc(userUid)
.collection('checkout_sessions')
.add({
'price': pd.priceId,
'quantity': pd.quantity,
'mode': 'payment',
'success_url': 'https://yourwebsite/purchase-complete',
'cancel_url': 'https://yourwebsite/payment-cancelled',
});
docRef.snapshots().listen(
(ds) async {
if (ds.exists) {
//check any error
var error;
try {
error = ds.get('error');
} catch (e) {
error = null;
}
if (error != null) {
print(error);
} else {
String url = ds.data()!.containsKey('url') ? ds.get('url') : '';
if (url != '') {
//open the url in a new tab
if (!isStripeUrlOpen) {
isStripeUrlOpen = true;
setState(
() {
loadingPayment = false;
},
);
launchUrl(Uri.parse(url));
}
}
}
}
}
},
);
}

Open an app in flutter based on the url provided in the email sent for verification

So I have been working on a flutter app and once the user registers through my app they are sent an email for the verification of their account. Once the url in the link is tapped they are verified. Now after their verification,the users must be redirected to the app. I looked into firebase dynamic links but in all of the articles,they were trying to share their app by generating a link. Is there a way I can implement this? Thanks in advance!
Use this package
https://pub.dev/packages/uni_links
For getting the link when the app is started.
This is the case in which your app was in the closed state.
Future<Null> initUniLinks() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
String initialLink = await getInitialLink();
// Parse the link and warn the user, if it is not correct,
// but keep in mind it could be `null`.
} on PlatformException {
// Handle exception by warning the user their action did not succeed
// return?
}
}
For listening to link clicks. This is for the case when your app is already open and you click the link.
_sub = getLinksStream().listen((String link) {
// Parse the link and warn the user, if it is not correct
}, onError: (err) {
// Handle exception by warning the user their action did not succeed
});
// NOTE: Don't forget to call _sub.cancel() in dispose()
}
Usually, you need to implement both of them together since your app may be in the closed state or open state while you click the link.
Future<Null> initUniLinks() async {
try {
String initialLink = await getInitialLink();
} on PlatformException {
}
_sub = getLinksStream().listen((String link) {}, onError: (err) {});
}}