How To Get Device Information With Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 30-10-2020

Futter comes with a library that helps us to get mobile device information using its library plugin i’e DeviceInfoPlugin

How To Get Device Information With Flutter Android App

Get Device Information 
Step 1:  
We cannot directly remove the time stamp from Get Device Information but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code

dependencies:
  flutter:
    sdk: flutter
  device_info: 0.3.0

Step 2: After done saving the pubspec.yaml file, Open your flutter project root folder in Command Prompt or Terminal and execute flutter pub get command. 

flutter pub get

Step 3: Open your project’s main.dart file and import material.dart and device_info: 0.3.0. dart package.
import 'package:device_info/device_info.dart';
Complete Code For Get Device Information In Flutter
main.dart
import 'package:flutter/material.dart';
import 'package:device_info/device_info.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  MyHomePageState createState() {
    return new MyHomePageState();
  }
}

class MyHomePageState extends State<MyHomePage> {
  DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  AndroidDeviceInfo androidInfo;

  fetchDeviceInfo() async {
    androidInfo = await deviceInfo.androidInfo;
  }

  @override
  void initState() {
    super.initState();
    fetchDeviceInfo();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.amber[900],
          title: Text('Get Device Information'
          )),
      body: Column(
        children: <Widget>[
          ListTile(
            title: Text('Manufacturer: ${androidInfo.manufacturer}, ',
              style: TextStyle(color: Colors.white
              ),),
          ),
          ListTile(
            title: Text('Product: ${androidInfo.product}, ',
              style: TextStyle(color: Colors.white
            ),),
          ),
          ListTile(
            title: Text('Android Version: ${androidInfo.version.codename}, ',
              style: TextStyle(color: Colors.white
              ),),
          ),
        ],
      ),
    );
  }
}

Related Post