Is there a way to detect flutter web is used in mobile browser?

Issue

I’m aware of Platform constants available to identify for which the flutter build is compiled to run.

But is there any way to identify the user is using the flutter web site in mobile?

Any help is appreciated, Thanks in advance.

Solution

I believe you can do it by checking both platform and screen size.
if platform is web and screen size is small, it’s definitely mobile browser.

GetX package also has a method named isPhone, you can use that too.

bool isTablet = context.isTablet;
bool isPhone = context.isPhone;
bool isAndroid = GetPlatform.isAndroid;
bool isIos = GetPlatform.isIOS;
bool isMacOs = GetPlatform.isMacOS;
bool isWindows = GetPlatform.isWindows;
bool isLinux = GetPlatform.isLinux;
bool isFuchsia = GetPlatform.isFuchsia;
bool isMobile = GetPlatform.isMobile;
bool isWeb = GetPlatform.isWeb;
bool isDesktop = GetPlatform.isDesktop;
bool isLandScape = context.isLandscape;
bool isPortrait = context.isPortrait;
double screenHeight = Get.height;
double screenWidth = Get.width;

Answered By – SinaMN75

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *