团体模式有问题

时间:2020-05-30 10:15:25

标签: flutter dart

class Categories extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 20),
      height: 150,
      child: ListView.separated(
        scrollDirection: Axis.horizontal,
        itemCount: categoryList.length,
        shrinkWrap: true,
        separatorBuilder: (context, index) => SizedBox(width: 10),
        itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () => BlocProvider.getBloc<CategoryBloc>().switchSelection(),
            child: StreamBuilder(
              stream: BlocProvider.getBloc<CategoryBloc>().categoryStream,
              builder: (context, snapshot) {
                return Container(
                    decoration: BoxDecoration(
                      color: snapshot.data ? Colors.orange : Colors.white,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(50),
                          topRight: Radius.circular(50),
                          bottomLeft: Radius.circular(50),
                          bottomRight: Radius.circular(50)),
                    ),
                    padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
                    child: CategoryColumn(index, snapshot));
              },
            ),
          );
        },
      ),
    );
  }
}

现在是问题所在。当我点击一个容器时,listview中的所有容器都会收到通知。如何仅对我点击的容器进行更改?

0 个答案:

没有答案