有没有一种方法可以在Flutter和Firestore中创建类别

时间:2019-11-29 22:54:47

标签: flutter

我正在用firestore来为我的商店应用创建类别部分,我已经能够在列表视图中检索所有类别,但是我想知道如何在onTap上检索每个类别集合。谢谢

这是为changeNotifier和firestore查询编写的代码

    class HorizontalCategoryWidget extends StatelessWidget {
      const HorizontalCategoryWidget({
        Key key,
        @required this.categoryNotifier
      }) : super(key: key);

      final CategoryNotifier categoryNotifier;

      @override
      Widget build(BuildContext context) {
        return ListView.builder(
          shrinkWrap: true,
          scrollDirection: Axis.horizontal,
          itemCount: categoryNotifier.categoryList.length,
          itemBuilder: (BuildContext context, int index) {
            return Padding(
              padding: const EdgeInsets.all(4.0),
              child: Container(
                height: 100,
                width: 80,
                child: GestureDetector(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Container(
                          padding: EdgeInsets.only(top: 4),
                          height: 40,
                          width: 80.0,
                          child: FadeInImage(
                            placeholder: AssetImage('assets/tsplaceholder.png'),
                            image: NetworkImage( categoryNotifier.categoryList[index].icon),
                            fit: BoxFit.contain,
                          ),
                        ),
                        SizedBox(height: 4,),
                        Text(
                          categoryNotifier.categoryList[index].categoryName,
                          style: TextStyle(fontSize: 12,fontWeight: FontWeight.bold),
                          maxLines: 1,
                          textAlign: TextAlign.center,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ],
                    ),
                    onTap: () {

                    }),
              ),
            );
          },
        );
      }
    }
  

这是用于从Firestore中检索所有类别的代码   水平列表视图

{{1}}

fsdb

0 个答案:

没有答案