How to ascertain whether the Flutter web app is running on phone or PC?

Issue

I want to use different apps on PC and mobile, so what would be the best way to find out what the device is before loading the app?

Solution

You can do this with the Platform class of of dart:io, which provides a few static properties that can help you determine the OS and therefore PC vs mobile.

The following return bools that help you determine each OS

isAndroid,
isFuchsia,
isIOS,
isLinux,
isMacOS,
isWindows

Or you can use the operatingSystem property, which returns a String containing the OS.

Ex.

if(Platform.isWindows)
...

In general, if you see Android & iOS as the OS, you’ll know it’s mobile. If you see Linux, MacOS, or Windows, you’ll know it’s PC. And Fuchsia is a bit ambiguous.

Answered By – Christopher Moore

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

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