Flutter分组的ListView

问题描述

我有一个Firebase数据库,其中包含2个相关集合:“产品” “类别”

我想在按类别进行分组的列表视图中显示产品。

每个产品文档中都有一个“类别”字段,即类别ID。

现在,我有以下代码可用于创建列表视图:

FullMenuNotifier fullMenuNotifier = Provider.of<FullMenuNotifier>(context);

ListView.builder(
            shrinkWrap: true,scrollDirection: Axis.vertical,itemBuilder: (BuildContext context,int index) {
              return Card(...);
  },itemCount: fullMenuNotifier.menuList.length,);

我使用以下代码从Firebase检索数据:

getMenu(FullMenuNotifier fullMenuNotifier)async{
  QuerySnapshot snapshot = await FirebaseFirestore.instance.collection('Products').get();
  List<FullMenu> _fullMenuList=[];
  snapshot.docs.forEach((element) {
    FullMenu fullMenu = FullMenu.fromMap(element.data());
    _fullMenuList.add(fullMenu);
  });
  fullMenuNotifier.menuList=_fullMenuList;
}

通知程序代码,

class FullMenuNotifier with ChangeNotifier{
  List<FullMenu>_menuList=[];
  FullMenu _currentMenu;

  UnmodifiableListView<FullMenu>get 
  menuList=>UnmodifiableListView(_menuList);
  FullMenu get currentMenu=>_currentMenu;
  set menuList(List<FullMenu>menuList){
    _menuList= menuList;
    notifyListeners();
  }
  set currentProduct (FullMenu fullMenu){
    _currentMenu= fullMenu;
    notifyListeners();
  }
}

Final result will look like this from grouped_list package

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...