为什么颤振联系人在小米设备上不起作用?
我是 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);
}
}
I'm new to Flutter and I'm trying to store contact list as name and number in local database. The code I wrote works on the Samsung A21S device that I use as an emulator, but it does not work on devices like Xiaomi, where did I go wrong?
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论