How to get Device info in Flutter

Posted by

The first goal for any developer should be to create apps that are compatible with as many devices as possible. It’s possible that occasionally our application won’t function on certain devices; in such cases, it’s ideal to collect device information. in order for developers to easily track and solve bugs using that log report.

Using the most awesome package, device_info_plus, which is accessible by pub get, we will learn how to obtain device information in this lesson.

About device_info_plus 

The device_info_plus package allows us to retrieve the most recent device information from within the Flutter application. which is compatible with a wide range of operating systems, including Windows, Linux, Android, iOS, and macOS.

Adding dependency

We need to add this package to pubspec.yaml and run the pub get command to get it into our flutter project.

Import Package

We can import the package and use its classes and functions when it has been installed in our Flutter app.

Create a DeviceInfoPlugin class Instance

As the main class in the package and the one with the majority of the methods, we should create an instance of the DeviceInfoPlugin class, as shown below.

Get the Device info from a Specific platform

After creating an instance of the DeviceInfoPlugin class, we can use the respected platform function to retrieve device information.

If we take the Android device information, this plugin obtains all of the information generated from ‘android.os.Build’.

Now, the device_info_plus package made sense to us. To gain more ideas, create a new Flutter project, replace the following code, and run the application.

After successfully running the application, we will get the following output as shown in the image below.

Click here to learn more about device_info_plus.

Thanks for reading … 

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x