I want to use device ID and pass to a FutureBuilder()
to perform some action.
Can anyone explain or provide some code to illustrate that?
I've tried using device_id flutter plugin but no luck.
I've checked with device_info but not sure how to use it properly with FutureBuilder
.
A device ID is a unique, anonymized string of numbers and letters that identifies every individual smartphone or tablet in the world. It is stored on the mobile device and can be retrieved by any app that is downloaded and installed.
You'll have to fully format your device data to change your Android phone's device ID. As the device ID is generated when you first set up the device, resetting the phone will change the Android device ID automatically.
Let me explain to you this by device_info plugin.
Step 1 Add Dependency
dependencies:
flutter:
sdk: flutter
device_info: ^0.4.0+1
Step 2 Import your file at the beginning
import 'package:device_info/device_info.dart';
Step 3 Create an async function to return device id.
deviceInfo() async{
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
return androidInfo.id;
}
Step 4 Create a FutureBuilder() to display device id or perform any action.
FutureBuilder(
future: deviceInfo(),
builder: (BuildContext context, AsyncSnapshot snap){
// do nothing...
if (snap.hasData){
//your logic goes here.
}else {
return new CircularProgressIndicator();
}
},
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With