这是我在device_info.dart文件中编写的代码(我正在尝试获取设备信息)。
import 'package:device_info/device_info.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import '../domain/model/model.dart';
Future<DeviceInfo> getDeviceDetails() async {
String name = "unknown";
String identifier = "unknown";
String version = "unknown";
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
try {
if (defaultTargetPlatform == TargetPlatform.android) {
//Android
AndroidDeviceInfo androidDeviceInfo = await deviceInfoPlugin.androidInfo;
name = "${androidDeviceInfo.brand} ${androidDeviceInfo.model}";
identifier = androidDeviceInfo.id;
version = androidDeviceInfo.version.codename;
}
if (defaultTargetPlatform == TargetPlatform.iOS) {
// iOS
IosDeviceInfo iosDeviceInfo = await deviceInfoPlugin.iosInfo;
name = "${iosDeviceInfo.systemName} ${iosDeviceInfo.model}";
identifier = iosDeviceInfo.identifierForVendor;
version = iosDeviceInfo.systemVersion;
}
} on PlatformException {
// return default data error
return deviceInfoPlugin(name, identifier, version);
}
return deviceInfoPlugin(name, identifier, version);
}
1.上面一行显示错误:表达式的计算结果不为函数,因此无法调用。(www.example.com上的device_info包pub.dev与dart >3不兼容,所以我使用了device_info_plus包)
1条答案
按热度按时间x7yiwoj41#
变更:
致:
deviceInfoPlugin
变量不是函数。它是DeviceInfoPlugin
的示例,并且已经包含了在if语句中定义的name
、identifier
和version
。