I create a flutter web app and use it as a PWA in my java-script website I opened it using iframe.
I want to close my PWA by tapping on a button by SystemChannels.platform.invokeMethod('SystemNavigator.pop')
.
I tried this code but not working:
GestureDetector(
onTap: () {
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
},
child: Container(padding: const EdgeInsets.all(4), child: Icon(Icons.close, color: BpColors.white, size: 20)),
);
I also tried using exit(0) but it makes the website to go to previous page not just closing the PWA.
2
Answers
This worked for me
close_clicked is the event name that my javascript is listening to.
It is not possible to close web app by
SystemChannels.platform.invokeMethod('SystemNavigator.pop')
because this only works for mobile applications. anyway, instead of it you can usewindow.close()
to close web app window. but unfortunately it may not working in some browsers because they do not allow to close window from JS for security reasons.By the way, there is a package named flutter_window_close you can try it.
happy coding…