flutter-universal-platform icon indicating copy to clipboard operation
flutter-universal-platform copied to clipboard

Mobile browser detection

Open coastalgit opened this issue 3 years ago • 6 comments

With the availability of Flutter 2, it would be hugely beneficial if the package could detect if it was running within a web browser on a mobile OS. Thus allowing users to restrict usage of their web app to desktop and prompting the user to utilize the equivalent mobile app from a Store.

coastalgit avatar Mar 15 '21 10:03 coastalgit

Is there any update on that? I have the same issue, I need to detect whether the user is in web(Desktop) or web(mobile,tablet)

omartinma avatar Apr 13 '21 11:04 omartinma

I have got around this for the moment by using the platform_detect package. It exposes a touchEvents property, which equates to true when running on Safari/iOS. If Apple releases a laptop with a touchscreen, then I will need to have a rethink!

coastalgit avatar Apr 13 '21 11:04 coastalgit

The issue is that the entire point of this plugin is that it can not access dart.io package, which is the easy way to sniff the current operating system.

I'll consider this touchEvents "hack", don't really love it.

esDotDev avatar May 05 '21 20:05 esDotDev

Any update on this?

polarby avatar May 17 '23 14:05 polarby

You can check the defaultTargetPlatform property on web, it returns TargetPlatform.iOS on web.

crizant avatar Aug 03 '23 05:08 crizant

Everyone, I have created a package for this purpose: simple_platform

Using this package, check for AppPlatform.isWeb && (DevicePlatform.isAndroid || DevicePlatform.isIOS), then you know it's mobile browser. Cheers~

crizant avatar Aug 06 '23 07:08 crizant