在这里我想获取设备信息,并在获取设备信息后将其传递到我的存储库文件中,以便每当我注册设备信息时都自动保存。
在此代码中,我想在deviceinfo中传递设备信息。
这是我尝试过的一些代码
class SignupRepository {
SignupRepository();
Future<SignupUser> signupUser(Map<String, dynamic> signUpUserMap) async {
Map<String, dynamic> signupUserRequestMap = {
"user": {
"email": signUpUserMap['email'],
"password": signUpUserMap['password'],
"mobile": "+918460666940",
"statusId": "confirmation_pending",
"profile": {"firstName": "Dipak", "lastName": "Savaliya"},
"install": {
"os": "iOS 11.3",
//Here i want to pass device info from device info class
"deviceInfo": {"device": "iPhone 7 Plus", "manufacture": "Apple"},
"deviceToken": "34214324213413423421",
"fcmToken": "1234234234231423421423424234123"
}
}
};
final QueryResult result = await GraphQLHelper.gqlMutation(
GQLStrings.signupUser(), signupUserRequestMap);
SignupUser signupUser = SignupUser.fromJson(result.data);
return signupUser;
}
}
这是获取设备信息的代码。当我运行此代码时,它将向我显示所有完美的设备信息。但是我需要在我的存储库类中传递此设备信息(存储库类代码如上所示)
class _DeviceinfoState extends State<Deviceinfo> {
static final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
Map<String, dynamic> _deviceData = <String, dynamic>{};
@override
void initState() {
super.initState();
initPlatformState();
}
Future<Null> initPlatformState() async {
Map<String, dynamic> deviceData;
try {
if (Platform.isAndroid) {
deviceData = _readAndroidBuildData(await deviceInfoPlugin.androidInfo);
} else if (Platform.isIOS) {
deviceData = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo);
}
} on PlatformException {
deviceData = <String, dynamic>{
'Error:': 'Failed to get platform version.'
};
}
if (!mounted) return;
setState(() {
_deviceData = deviceData;
});
}
Map<String, dynamic> _readAndroidBuildData(AndroidDeviceInfo build) {
return <String, dynamic>{
'version.securityPatch': build.version.securityPatch,
'version.sdkInt': build.version.sdkInt,
'version.release': build.version.release,
'version.previewSdkInt': build.version.previewSdkInt,
'version.incremental': build.version.incremental,
'version.codename': build.version.codename,
'version.baseOS': build.version.baseOS,
'board': build.board,
'bootloader': build.bootloader,
'brand': build.brand,
'device': build.device,
'display': build.display,
'fingerprint': build.fingerprint,
'hardware': build.hardware,
'host': build.host,
'id': build.id,
'manufacturer': build.manufacturer,
'model': build.model,
'product': build.product,
'supported32BitAbis': build.supported32BitAbis,
'supported64BitAbis': build.supported64BitAbis,
'supportedAbis': build.supportedAbis,
'tags': build.tags,
'type': build.type,
'isPhysicalDevice': build.isPhysicalDevice,
};
}
Map<String, dynamic> _readIosDeviceInfo(IosDeviceInfo data) {
return <String, dynamic>{
'name': data.name,
'systemName': data.systemName,
'systemVersion': data.systemVersion,
'model': data.model,
'localizedModel': data.localizedModel,
'identifierForVendor': data.identifierForVendor,
'isPhysicalDevice': data.isPhysicalDevice,
'utsname.sysname:': data.utsname.sysname,
'utsname.nodename:': data.utsname.nodename,
'utsname.release:': data.utsname.release,
'utsname.version:': data.utsname.version,
'utsname.machine:': data.utsname.machine,
};
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text(
Platform.isAndroid ? 'Android Device Info' : 'iOS Device Info'),
),
body: new ListView(
shrinkWrap: true,
children: _deviceData.keys.map((String property) {
print('${_deviceData[property]}');
return new Row(
children: <Widget>[
new Container(
padding: const EdgeInsets.all(10.0),
child: new Text(
property,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
new Expanded(
child: new Container(
padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
child: new Text(
'${_deviceData[property]}',
overflow: TextOverflow.ellipsis,
),
)),
],
);
}).toList(),
),
),
);
}
}