I'm using url_launcher to show the webview inside the app to do the payment, After completion of the payment I have to navigate back to the previous screen. Is there any possibility to do this? Should it be handled from webview or mobile app?
This is the way that im using to show webview
_launchURL(onboardingLink) async {
await canLaunch(onboardingLink)?
await launch(onboardingLink,
enableJavaScript: true,
forceWebView: true)
: throw 'Could not launch $onboardingLink';
}
USE THIS
_onUrlChanged =
flutterWebviewPlugin.onUrlChanged.listen((String url) async {
if (mounted) {
//print("URL changed: $url");
if (url.startsWith(paymentSuccessUrl)) {
// handle success case
} else if (if (paymentCancelUrl)) {
// Handle cancel case
}
}
Related
I'm having an issue dealing with Firebase push notifications when the App is KILLED.
What's happening:
First of all, push notifications should work like this. When you tap, you are redirected to a Move-Type Job or an Event-Type Job.
When app is in BACKGROUND MODE, push notification shows as it should,
and it redirects to the page that it should.
When App is KILLED, push notifications still shows, but when you tap on them you are not redirected, you are just opening the App.
Future initialize() async {
await getConnectivity();
if (hasInternet) {
try {
await configurePushNotificationHandlers();
} catch (e) {
hasApiConnection = false;
}
}
}
Future configurePushNotificationHandlers() async {
await navigationService.navigateReplacementWithParams(ErrorPage());
await _firebaseMessaging.requestPermission(
alert: true,
badge: true,
provisional: false,
sound: true,
);
String fbToken = await _firebaseMessaging.getToken();
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
if (message.data != null && message.data.containsKey('showInPageNotification')) {
numberOfNotifications++;
}
notifyListeners();
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
print('A new onMessageOpenedApp event was published!');
if (message.data != null && message.data.containsKey('job_id')) {
String jobId = message.data['job_id'];
String jobType = message.data['job_type'];
jobType = jobType.toLowerCase();
if (jobType == 'move') {
await goToJobDetail(jobId);
} else {
await goToEventDetail(jobId);
}
}
});
Anyone has a clue of why does this happens? Push notifications are working fine, it's the redirection the current ISSUE. Thanks!
Use FirebaseMessaging.instance.getInitialMessage() method to get messages
If App is Closed/Killed
FirebaseMessaging.instance
.getInitialMessage()
.then((RemoteMessage message) {
print("FirebaseMessaging.getInitialMessage $message");
});
Try this and let me know.
I am implementing a password recovery function based on the url sent to the email. Opening the app based on that url was successful. But instead of directly opening the required page in the app that is in the background, it duplicates the app. Although it still leads me to the password recovery page, now there will be 2 same apps running side by side
Procedure
Enter your email to send the password reset link
Click submit
Open the email containing the recovery link
Duplicate the app and open a recovery password page
Things what happen
Splash screen, first page open in the app, I am trying to do as instructed from uni_links package but still no success. Currently the function getInitialLink has the effect of opening the app based on the recovery link
class SplashController extends GetxController {
final SharedPreferencesHelper _helper = Get.find<SharedPreferencesHelper>();
late StreamSubscription sub;
#override
void onReady() async {
super.onReady();
await checkToken();
}
Future<void> checkToken() async {
await Future.delayed(Duration(seconds: 3));
var token = _helper.getToken();
if (token == null) {
Get.offNamed(Routes.LOGIN);
} else {
Get.offNamed(Routes.MAIN);
}
}
#override
void onInit() {
super.onInit();
initUniLinks();
}
Future<Null> initUniLinks() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
String? initialLink = await getInitialLink();
if (initialLink != null) {
print("okay man");
Get.toNamed(Routes.RECOVERY);
}
sub = getLinksStream().listen((link) {
}, onError: (err) {
});
} on PlatformException {
// Handle exception by warning the user their action did not succeed
// return?
}
}
}
I found the solution, actually this answer is already on Stackoverflow, and it's really simple.
In the AndroidManifest.xml file of the app. Find "android:launchMode" and change its old value to singleTask. And here is the result
android:launchMode="singleTask"
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?
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';
}
}
i used firebase admob plugin to show the ads. I was implemented rewarded video ads. I want to implement when we click on button this shows ads and after completing the ads we go on next page with some value. I used this
RewardedVideoAd.instance
.show()
.whenComplete(uploadData(someData));
However, this does not work.
After that I created this method and used it but this is also not working
Future myVideo(var myNumber) async {
await RewardedVideoAd.instance.show();
uploadData(somedata);
}
anyone know how to create this after succesful completed video ads call method or we go on next page until not ?
Please add rewarded video listener and in that you may add your method after completing your ads like that
RewardedVideoAd.instance.listener =
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.rewarded) {
setState(() {
_coins += rewardAmount;
uploadData(someData);
});
} else if (event == RewardedVideoAdEvent.completed) {
setState(() {
uploadData(someData);
});
} else if (event == RewardedVideoAdEvent.closed) {
setState(() {
uploadData(someData);
});
}
};