1 year ago

#256527

test-img

Edward

Why flutter contacts don't work on Xiaomi device?

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);
  
  }
}

arp

nt

0 Answers

Your Answer

Accepted video resources