Reputation: 291
I am using flutter web to make a web app, and I want to know whether the user has actually installed the web app or whether the web app is being run on a browser..
I want to know this so I can allow special features to users that have installed the web app in their devices. (e.g allow local_notifications which is not possible for flutter running on a browser)
Upvotes: 2
Views: 2391
Reputation: 37342
To extend on Eric Kwok's answer -
import 'dart:html' as html;
bool isPwa() {
return html.window.matchMedia('(display-mode: standalone)').matches;
}
References -
Upvotes: 0
Reputation: 41
Use JavaScript. Insert this HTML code to your index.html
<script>
function isPwaInstalled() {
return window.matchMedia('(display-mode: standalone)').matches;
}
</script>
Then in your dart file
import 'dart:js' as js;
bool isPwaInstalled() => js.context.callMethod("isPwaInstalled");
When your PWA app is installed to desktop this method will return true.
Note that the dart:js
lib is available only on Flutter web, if you import it on other platforms such as iOS or Android, the compiler will complains about it. To avoid this, see Conditional Import or this blog
Upvotes: 4
Reputation: 2321
Adding a Safari Shortcut from a WebApp to HomeScreen is nothing like installing it. It just opens your WebApp in Safari browser
You can check the device with platform_detect 2.0.0
package thought but that's about it
Link to package https://pub.dev/packages/platform_detect
Upvotes: 1