1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
import 'dart:io'; import 'package:device_info/device_info.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart';
class DeviceDetailDemo extends StatefulWidget {
@override _DeviceDetailDemoState createState() => _DeviceDetailDemoState(); }
class _DeviceDetailDemoState extends State<DeviceDetailDemo> {
String deviceName =''; String deviceVersion =''; String identifier= '';
Future<void>_deviceDetails() async{ final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin(); try { if (Platform.isAndroid) { var build = await deviceInfoPlugin.androidInfo; setState(() { deviceName = build.model; deviceVersion = build.version.toString(); identifier = build.androidId; }); } else if (Platform.isIOS) { var data = await deviceInfoPlugin.iosInfo; setState(() { deviceName = data.name; deviceVersion = data.systemVersion; identifier = data.identifierForVendor; }); } } on PlatformException { print('Failed to get platform version'); }
}
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.redAccent[100], title: Text("Flutter Device Details Demo"), automaticallyImplyLeading: false, ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ RaisedButton( padding: EdgeInsets.all(14), color: Colors.cyan[50], onPressed: (){ _deviceDetails(); }, child: Text("Device Details", style: TextStyle(color: Colors.black),), ), deviceVersion.isNotEmpty && deviceName.isNotEmpty && identifier.isNotEmpty? Column( children: [ SizedBox(height: 30,), Text("Device Name:- "+deviceName,style: TextStyle (color: Colors.red, fontWeight: FontWeight.bold)), SizedBox(height: 30,), Text("Device Version:- "+deviceVersion,style: TextStyle (color: Colors.red, fontWeight: FontWeight.bold)), SizedBox(height: 30,), Text("Device Identifier:- "+identifier,style: TextStyle (color: Colors.red, fontWeight: FontWeight.bold)), SizedBox(height: 30,), ], ): Container(), ], ), ), ); } }
|