I’ve seen a number of posts asking about detecting the browser and os in Flutter apps which suggest plugins such as client_information and device_info_plus. However, what I haven’t seen is how to detect these things all while running a Flutter web app.
My use-case is that I’d like to prompt the user to add my web app to their home screen. To do that I need to know their OS (don’t want to prompt a macOS user to do this), and browser (Looks like this is a temporary requirement, as currently only safari can install web apps on the home screen so I need to direct them to open my app with Safari, but with iOS 16.4 launching soon third-party browsers will be able to do this as well).
Is there a way to do this?
2
Answers
You can use the
defaultTargetPlatform
variable from theflutter foundation
package.You can get the
user agent
string, which contains information about the operating system and browser:Output:
In addition, you can use user_agent_parser to extract information from the output.