这是为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}}