Home > front end >  Is there a way to detect flutter web is used in mobile browser?
Is there a way to detect flutter web is used in mobile browser?

Time:09-22

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.

CodePudding user response:

You can check device_info_plus package, specifically WebBrowserInfo class for some related information.

CodePudding user response:

You can use the TargetPlatform class from package:flutter/foundation.dart, for example:

defaultTargetPlatform == TargetPlatform.iOS
or
defaultTargetPlatform == TargetPlatform.android

CodePudding user response:

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;
  • Related