我是 Flutter 的新手,我正在尝试将联系人列表作为姓名和号码存储在本地数据库中。我编写的代码在我用作模拟器的三星 A21S 设备上运行,但在小米之类的设备上运行,我哪里出错了?
void getContacts() async {
List<Contact>? _contacts;
List<String> contactList = [];
final bool isConnected = await InternetConnectionChecker().hasConnection;
if (isConnected) {
_contacts = await FlutterContacts.getContacts(
withThumbnail: false, withPhoto: false, withProperties: true);
for (var i = 0; i < _contacts.length; i++) {
//Error this line
var num = _contacts[i].phones.first.normalizedNumber;
var name = _contacts[i].displayName;
var nameNum = "$name,$num";
contactList.insert(i, nameNum);
}
print(contactList);
print(contactList.length);
String json = jsonEncode(contactList);
}
}