flutter MultiSelectBottomSheetField 推送当前数据时芯片不显示

问题描述 投票:0回答:0

我正在尝试修复我的代码,但到目前为止我还没有找到任何解决方案。我做了很多研究,甚至使用了 AI,但到目前为止还没有解决方案。 让我给你更多的颜色。

我正在使用 Firebase。我有一个包含地图数组的文档。他们的钥匙是姓名、电话、电子邮件。

显示视图时,我正在获取数据。我还在列表中收集我手机的所有联系人。我只需要再次提供姓名、电子邮件和电话号码。

我想要实现的是,当显示 UI 时,我的芯片只有所选联系人的姓名(来自 firebase 的联系人)。我附上屏幕截图以使其更清晰。

List <MultiSelectItem<dynamic>> allContactsFromPhone = [];
List<MultiSelectItem<dynamic>> currentContacts = [];

 child: MultiSelectBottomSheetField(
                                      isDismissible: false,
                                      selectedColor: theme.primaryColor,
                                      backgroundColor: theme.backgroundColor,
                                      key: _multiSelectKeyContact,
                                      initialChildSize: 0.7,
                                      maxChildSize: 0.95,
                                      buttonIcon: const Icon(
                                          Icons.arrow_downward_outlined),
                                      title: Text(
                                        'Delegated to:',
                                        style: theme.textTheme.bodyText1,
                                      ),
                                      buttonText: Text('Choose who you delegate to',
                                          style: theme.textTheme.headline6),
                                      searchTextStyle:
                                      theme.textTheme.headline6,
                                      searchHintStyle:
                                      theme.textTheme.headline6,
                                      itemsTextStyle: theme.textTheme.headline6,
                                      selectedItemsTextStyle:
                                      theme.textTheme.headline6,
                                      items: allContactsFromPhone,
                                      initialValue: currentContacts,
                                      searchable: true,
                                      onConfirm: (valueContact) {
                                        setState(() {
                                          _contactSelected = (valueContact);
                                        });
                                        _multiSelectKeyContact.currentState!.validate();
                                      },
                                      chipDisplay:  MultiSelectChipDisplay(
                                        chipColor: theme.primaryColorLight,
                                        textStyle: theme.textTheme.bodyText1,
                                        onTap: (dynamic item) {
                                          setState(() {});
                                          _multiSelectKeyContact.currentState!.validate();
                                        },
                                      ),
                                    ),
WidgetsBinding.instance!.addPostFrameCallback((_) async {
      final deviceContacts = await getContactsFromDevice();
      setState(() {
        allContactsFromPhone = deviceContacts!.map((e) => MultiSelectItem(e, e.displayName)).toList();
      });
    });
currentContacts = widget.myDocument.delegated_To!
        .map((contact) => MultiSelectItem<dynamic>(contact, contact.name))
        .toList();


 Future<List<Contact>?> getContactsFromDevice() async {
    final contacts = await getContact();
    return contacts?.toList();
  }


flutter firebase multi-select
© www.soinside.com 2019 - 2024. All rights reserved.