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());
If you got something wrong? Mention it in the comments. I would love to improve. your support means a lot to me! If you enjoy the content, I’d be grateful if you could consider subscribing to my YouTube channel as well.
I am Shirsh Shukla, a creative Developer, and a Technology lover. You can find me on LinkedIn or maybe follow me on Twitter or just walk over my portfolio for more details. And of course, you can follow me on GitHub as well.
Have a nice day!🙂