1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Why is the group list empty even though this contact is a member of a group?

Discussão em 'Mobile' iniciado por Stack, Outubro 10, 2024 às 03:42.

  1. Stack

    Stack Membro Participativo

    I have grouped the contacts, but when I run the print() command in the console, the list of groups is empty. Why is the group list empty even though this contact is a member of a group?

    [​IMG]

    import 'package:flutter/material.dart';
    import 'package:flutter_contacts/contact.dart';
    import 'package:flutter_contacts/flutter_contacts.dart';

    class ContactsPage extends StatefulWidget {
    const ContactsPage({super.key});

    @override
    State<ContactsPage> createState() => _ContactsPageState();
    }

    class _ContactsPageState extends State<ContactsPage> {
    List<Contact> _contacts =[];

    @override
    void initState() {
    super.initState();
    _fetchContacts();
    }

    Future _fetchContacts() async {
    if (!await FlutterContacts.requestPermission()) {
    } else {
    List<Contact> contacts = await FlutterContacts.getContacts();
    setState(() => _contacts = contacts);
    print(_contacts);
    }
    return _contacts;
    }


    @override
    Widget build(BuildContext context) {
    return Scaffold(
    body: FutureBuilder(
    future: _fetchContacts(),
    builder: (BuildContext context, index) {
    return ListView.builder(
    itemCount: _contacts.length,
    itemBuilder: (BuildContext context, int index) {
    return ListTile(
    title: Text(_contacts[index].groups[0].name),
    );
    }, );
    },),
    );
    }
    }


    console result:

    I/flutter ( 9205): [Contact(id=253, displayName=A. H pahlozadeh, thumbnail=null, photo=null, isStarred=true, name=Name(first=, last=, middle=, prefix=, suffix=, nickname=, firstPhonetic=, lastPhonetic=, middlePhonetic=), phones=[], emails=[], addresses=[], organizations=[], websites=[], socialMedias=[], events=[], notes=[], accounts=[], groups=[])

    Continue reading...

Compartilhe esta Página