Using uni_links when the app is in the background - flutter

My application has the following structure:
- InheritedWidget for dependencies
--> Splash Screen Page
--> Login Pages
--> Main Pages
When the app runs for the first time, I can use var link = await getInitialLink(); to get the value for the link that opened the app.
However, I cannot get the same result if I open the app on the background.
I tried to use
getLinksStream().listen((link) => (link) {
try {
var _latestUri;
if (link != null) _latestUri = Uri.parse(link);
print("=== Formated successfully a link!");
} on FormatException {
print("--- A link got here but was invalid");
}
});
For getting the link in the Splash Screen, but if the app is already open in the Login or Main pages, it won't go through the Splash Screen again.
Then, I tried to put it in the InheritedWidget, but alas, didn't get any result whatsoever.
So my question is: Where and how should I set up uni_links so that I can catch all incoming links even if the app is open?
Or better, is there an alternative for App Links/Universal Links that I can use?

Though it's not the best and most elegant way, I got around this.
First, I was not using getLinksStream correctly
Instead of
(link) => (link) {...}
It's
(link) {...}
Then, I need to put this subscription in my Splash Screen and do not dispose of it, so that it can listen to new events.
If anybody has a better solution, please free to add it

For this situation, you need to use both of getInitialUri() and getUriLinksStream(),
If app launchs directly u will get uri from getInitialUri, if app already running on background u will get uri from getUriLinksStream.

Related

Not receiving firebase dynamic link

Currently I am doing a project that calls a secondary app and I launch the 2nd app through InAppWebView. While the 2nd app is facing the user, the inappwebview is still running and sends live update, which I am capturing to trigger events, for example like it will send payment complete, allowing me to trigger to go summary page.
The issue I am having is, I am unable to smoothly transit back to my app. So there are two ways that I found that allow me to go back to the app.
One, launch the URL using my dynamic link but this method I am unable to receive the link.
Second, to launch it through external application like chrome.
The second method works perfectly other than the fact that the screen jumps to chrome. And it continues from where I left off.
However, what I want is both, continue from where I left off and not have the jumping of the chrome. Or from what I have read the right way is to direct to the activity using intent filter. But the smooth method I am not receiving the links but the jump method I am receiving the links.
Please help T - T
if you need to add dynamic links with firebase you can find the setup right in the docs and with the help with firebase_dynamic_links you can handle where to go inside your app and also can execute parameters from the link in the function below you make a stream that listen to any dynamic link clicked while the app in the background or foreground , the PendingDynamicLinkData is when the app terminated. the business logic and how the app interacts ups to you.
static Future<void> initDynamicLink() async {
FirebaseDynamicLinks.instance.onLink.listen((dynamicLink) async {
if (dynamicLink.link != Uri.parse("uri")) {
log(dynamicLink.link.queryParameters.toString());
final Uri deepLink = dynamicLink.link;
// you should handle the navigation or you logic here
}
}).onError((error) {
debugPrint("error from dynamic link Stream : : :: ${error.toString()}");
});
final PendingDynamicLinkData? initialLink =
await FirebaseDynamicLinks.instance.getInitialLink();
try {
if (initialLink != null) {
log(initialLink.link.toString());
final Uri deepLink = dynamicLink.link;
// you should handle the navigation or you logic here
}
} catch (e) {
debugPrint('No deepLink found');
}
}
don't forget to call this function in the main like this
void main()async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
initDynamicLink();
}

How to open the bottom sheet that contains the list of applications for opening URL or google map. So the user can select their preferred application?

I tried this one. But, it Directly opens on the Google Maps application. The bottom sheet for choosing the preferred application is not showing. How do I achieve it? So, the user can select their preferred application.
This is my code for now,
try {
launchUrl(
Uri.parse("geo:${taskAddress.lat},${taskAddress.lng}"),
mode: LaunchMode.externalApplication,
);
} catch (e) {
} finally {
launchUrl(Uri.parse(
"google.navigation:q=${taskAddress.lat},${taskAddress.lng}&mode=d"));
}
I think you can't do that. It's user device preferred setting. If the user set it to "Always Open" or similar it will not ask again.

How can I receive return data from a HTML popup on Flutter Web

I am working on a plugin that launches a WebView to carry out some auth verification. Using the webview_flutter plugin, it works fine on Android and iOS once I call the runJavascriptReturningResult function. It returns the document.getElementById('return').innerText and then I parse the result. But on Flutter web, the webview_flutter_web does not currently support runJavascriptReturningResult, so it throws a platform error once invoked.
I tried using an HTML Popup, but I don't know how to extract the return data before the popup closes.
My implementation for the popup is like this:
html.WindowBase _popup = html.window.open(url, name,'left=100,top=100,width=800,height=600');
if (_popup.closed!) {
throw("Popups blocked");
}
How do I get the return data before the popup closes? Is there another way to do this on Flutter Web?
Maybe listening beforeunload event on the new window and getting the return value before it closes.
The solution was to listen to onMessage. Then get the event data from it.
html.window.open(url!, 'new tab');
html.window.onMessage.listen((event) async {
log(event.data.toString()); // Prints out the Message
});

How to Tap on native iOS popup to allow Notifications. (Flutter Integration Test)

Flutter Driver code has to tap on the native "Allow" button to continue and simulate the correct user behaviour.
See this screenshot. Native iOS popup before app starts - Allow Notifications
App has not yet completely started and is waiting for this tap.
How does one get the driver to tap on the native iOS popup?
Any suggestions and ideas are welcome.
Here is the code for one attempt to wait for the app before continuing with other tests; it just awaits indefinitely:
setUpAll(() async {
driver = await FlutterDriver.connect();
await driver.waitUntilFirstFrameRasterized();
});
Here is another attempt at finding the word "Allow" in the popup and tapping on it:
test('Allow app to send Notifications.', () async {
final allow = find.byTooltip("Allow");
await delay(750);
await driver.tap(allow);
});
It does not find the word.
The issue is probably that Flutter Driver is not aware of the iOS native popup.
Other tests are very simple once in the app, for example, to tap on fields, enter text, scroll pages, etc.
Any ideas on how to do this?
Unfortunately this feature is currently not possible. Flutter Driver can't interact with native elements (v1.20.4).
https://github.com/flutter/flutter/issues/34345
https://github.com/flutter/flutter/issues/12561

Running the google places modal popup in flutter

Looking at the flutter code it seems like I should be able to run the google places modal dialog since it does a full screen thing and doesn't try and overlay on top of flutter.
However I am having an issue where the modal shows up and then disappears again immediately. I am not entirely sure how to solve this...
I am activating it with:
call.method == "openPlacesDialogModal" -> {
val code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity)
if (GoogleApiAvailability.getInstance().showErrorDialogFragment(activity, code, REQUEST_GOOGLE_PLAY_SERVICES)) {
return
}
//val intent = Intent(activity, PlacesActivity::class.java)
//activity.startActivity(intent)
var intentBuilder = PlacePicker.IntentBuilder()
activity.startActivityForResult(intentBuilder.build(activity), PLACE_PICKER_REQUEST)
placeResult = result
return
}
In the logs I get:
I/FlutterActivityDelegate(18184): onResume setting current activity to this
I/flutter (18184): Opening picker
I/FlutterActivityDelegate(18184): onResume setting current activity to this
I think it is the onResume getting back to the ActivityDelegate that is the issue.
I put this on top of a completely different activity too, which kind of works. It shows the dialog for longer. I made sure I have all the right permissions, I have the fine location, internet permissions. Do I need to setup anything else?
Thanks,
David.
Error here was that I was not setting up the google api correctly and it was erroring immediately. Had to put in some checks to look for this error so I could respond correctly to the app that an error occurred.