I have created an app on all 3 platforms: iOS, Android and Web. I also have manifest.json
and other things required for PWA
. I have deployed it to firebase hosting. Now what I want to do is manually trigger the Add to Home screen on tap of a button. The real problem is though all the articles shows code to be paste on JS side while I have all the UI in dart so How do I listen for beforeinstallprompt
and trigger add to home screen manually ? I'm struggling with this from last 3 days but no luck. I have this package installed universal_html: ^1.2.3.
If anyone knows how to do this please help me out.
Asked
Active
Viewed 169 times
0

ch271828n
- 15,854
- 5
- 53
- 88

Rahul Vyas
- 28,260
- 49
- 182
- 256
1 Answers
0
What about writing those code in normal JavaScript, and then call it from Dart(flutter web).
There are many resources about that. For example, Flutter Web : How to run javascript using dart js
In addition, do not forget that, when you are writing Flutter web, you have the full control over the HTML/JS/CSS/Dart. Thus nothing can stop you from writing JS code :)

ch271828n
- 15,854
- 5
- 53
- 88
-
but in my case it's different. What we have here is a listener in javascript which will prevent default add to home screen prompt and then show a button/banner to user on Landing page in dart code. From that button I need to trigger add to home prompt again. – Rahul Vyas Dec 31 '20 at 11:20
-
One more thing is web import and native import doesn't work together. The whole app is written in dart. – Rahul Vyas Dec 31 '20 at 11:21
-
@RahulVyas I am confused. What about writing your JS, and then let js call dart? – ch271828n Dec 31 '20 at 11:30
-
yes I think we need vice versa calling. First listen to 'beforeinstallprompt' in JS and then call dart function (I'm not sure where I need to write code for it). Let me explain you the flow. Step 1 - listen to 'beforeinstallprompt' in JS Step 2 - call some code in dart file on landing page or whatever page the user is in Step 3 - Show some banner UI through dart code executed in step 2 Step 4 - from dart banner on tap of button execute add to home prompt in JS or Dart if possible – Rahul Vyas Dec 31 '20 at 11:32
-
@RahulVyas then what about this https://stackoverflow.com/questions/23104432/how-to-call-a-dart-function-from-javascript – ch271828n Dec 31 '20 at 11:34
-
also do you know how we can detect in dart that we're running app on mobile browser not desktop browser ? – Rahul Vyas Dec 31 '20 at 11:35
-
@RahulVyas then this https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser – ch271828n Dec 31 '20 at 11:36
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/226654/discussion-between-rahul-vyas-and-ch271828n). – Rahul Vyas Dec 31 '20 at 11:38
-
please reply in chat – Rahul Vyas Dec 31 '20 at 11:46