Home > Software engineering >  How can ı get the Device İnformation on my Flutter app?
How can ı get the Device İnformation on my Flutter app?

Time:07-23

hi guys i want to show my device model inside my flutter app. I used device_info_plus package but it didn't work. How can I do that?

CodePudding user response:

Into your pubspec.yaml add the device_info package:

    dependencies:
      flutter:
        sdk: flutter
      device_info: ^2.0.3

in your dart code just add this and will see device information:

  import 'package:device_info/device_info.dart';


  showInfoDevice(){
    String deviceInfo;
    if (Platform.isIOS) {
        IosDeviceInfo iosInfo =
            await DeviceInfoPlugin().iosInfo;
        deviceInfo = iosInfo.utsname.machine;
    } else {
      AndroidDeviceInfo androidInfo =
          await DeviceInfoPlugin()
               .androidInfo;
      deviceInfo = androidInfo.model;
    }
    print(deviceInfo);
 }
 
 void initState(){
      super.initState();
      showInfoDevice();
 }

CodePudding user response:

As of now please use this package:

dependencies:
      flutter:
        sdk: flutter
      device_info_plus: ^4.0.1

Link: https://pub.dev/packages/device_info_plus

CodePudding user response:

Thank you guys. I solved the problem. I tried again by researching the device_info_plus package a bit more. It's work!

  • Related