gskinnerTeam / flutter-universal-platform

A web-safe implementation of dart.io.Platforms. Helps avoid the "Unsupported operation: Platform._operatingSystem" runtime error.
MIT License
105 stars 27 forks source link

Mobile browser detection #11

Open coastalgit opened 3 years ago

coastalgit commented 3 years ago

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.

omartinma commented 3 years ago

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)

coastalgit commented 3 years ago

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!

esDotDev commented 3 years ago

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.

polarby commented 1 year ago

Any update on this?

crizant commented 1 year ago

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

crizant commented 1 year ago

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~