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

[Flutter] Why does the group field(label) remain empty when I insert a new contact?

Discussão em 'Mobile' iniciado por Stack, Outubro 13, 2024 às 07:02.

  1. Stack

    Stack Membro Participativo

    I want to add a new contact and specify the group argument. With this piece of code and according to the result of the print() command, everything seems correct, but when I refer to the created contact, I notice that the field group (label) is empty.

    My code:

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

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

    @override
    State<InsertContact> createState() => _InsertContactState();
    }

    class _InsertContactState extends State<InsertContact> {

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

    Future<void> _insertContact() async {
    if (!await FlutterContacts.requestPermission()) {
    } else {
    final newContact = Contact()
    ..displayName ='Ehsan Zarei'
    ..name.first = 'Ehsan'
    ..name.last = 'Zarei'
    ..phones = [Phone('123456789')]
    ..groups= [Group('444', 'Edu')];
    await newContact.insert();
    print(newContact);
    }

    }

    @override
    Widget build(BuildContext context) {
    return const Placeholder();
    }
    }


    console result:

    I/flutter ( 7976): Contact(id=, displayName=Ehsan Zarei, thumbnail=null, photo=null, isStarred=false, name=Name(first=Ehsan, last=Zarei, middle=, prefix=, suffix=, nickname=, firstPhonetic=, lastPhonetic=, middlePhonetic=), phones=[Phone(number=123456789, normalizedNumber=, label=PhoneLabel.mobile, customLabel=, isPrimary=false)], emails=[], addresses=[], organizations=[], websites=[], socialMedias=[], events=[], notes=[], accounts=[], groups=[Group(id=444, name=Edu)])


    result in device: [​IMG]

    Continue reading...

Compartilhe esta Página