device_info

Get information regarding your device like android, ios or windows

In this article, we will discuss, how to get some important information regarding over device,

Means flutter is a hybrid language and using this we will create applications for android, ios, mac os, and windows applications.

So sometimes we are writing code accordingly to a specific OS. Like some lines of code for android or ios.

Also for some other uses, we needed this information.

So come the main point,
There is a library available for getting this information easily

This is device_info

After adding this library and import this,

We can get information in easily

import 'package:device_info/device_info.dart’;

DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();

AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; print(’Running on ${androidInfo.model}’); // e.g. "Moto G (4)"

IosDeviceInfo iosInfo = await deviceInfo.iosInfo; print(’Running on ${iosInfo.utsname.machine}’); // e.g. "iPod7,1"

For a complete example click here

But there is also some custom option available if you want to get only device name.
Like this
for a more simple way for web and app both.
try this

import 'dart:io' show Platform;

import 'package:flutter/foundation.dart' show kIsWeb;

var platformName = '’;

if (kIsWeb) {

platformName = "Web";

} else {

if (Platform.isAndroid) {

platformName = "Android";

} else if (Platform.isIOS) {

platformName = "IOS";

} else if (Platform.isFuchsia) {

platformName = "Fuchsia";

} else if (Platform.isLinux) {

platformName = "Linux";

} else if (Platform.isMacOS) {

platformName = "MacOS";

} else if (Platform.isWindows) {

platformName = "Windows";

}

}

print("platformName :-"+platformName.toString());

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store