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

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
});

Related

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

Using uni_links when the app is in the background

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.

Hard browser refresh using nwjs on Mac

Is there a way to do a hard browser refresh when running an app with nwjs, on Mac? nwjs's right click 'simulate browser restart' seems to start the app at its entrypoint again. Is there a way to simulate the behavior of simply clicking the shift reload button in Chrome?
There is an nwjs api for this:
// Load native UI library
var ngui = require('nw.gui');
// Get the current window
var nwin = ngui.Window.get();
// this will do a hard refresh
nwin.reloadIgnoringCache();
// here's a regular refresh
nwin.reload();
nwjs doc:
http://docs.nwjs.io/en/latest/References/Window/#winreloadignoringcache
just use javascript reload
location.reload();

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.

How to add Google analytics to android app widget?

I've been struggle to had Google analytics to my app widget, without any success, The code works fine when using from Activity but not from the app widget.
Hi use this code inside your AppWidgetProvider onEnabled() method
Tracker t = ((MyApplication) context.getApplicationContext()).getTracker(
MyApplication.TrackerName.APP_TRACKER);
// Set screen name.
t.setScreenName(screenName);
// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());