1

I shared my web-app link on a Facebook post, my users click on this link and the page opens in Facebook webview. I want to alert them "You are viewing this page in Facebook browser, please open Chrome/Safari to run this web app".

How can I do this with Flutter?

I have searched many questions and answers but they just check if the page runs in Web, not in Webview!

JasonSG
  • 11
  • 1

1 Answers1

0

you can simply check it like this:

import 'package:flutter/foundation.dart';

    if (kIsWeb && (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.android)) {
          /// you open your alert dialog to tell the user what you want
    }

this works because if link of your webapp is opened in the facebook app, it will be on a mobile device, if the user is using facebook web, it won't be using a webview.

AJ-
  • 1,638
  • 1
  • 24
  • 49
  • Can you tell me which package to import? – JasonSG Mar 18 '23 at 05:30
  • It's not working because in Facebook webview, it's still the web, not Android or iOS – JasonSG Mar 18 '23 at 06:09
  • @JasonSG I edited my answer, the current check now tells you if your `webapp` has been opened on a web page (either webview or browser) but while on a mobile device – AJ- Mar 18 '23 at 08:55