You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
30 lines
1.1 KiB
import 'package:flutter/material.dart';
|
|
import 'package:thesis_shop/bloc/cart_bloc.dart';
|
|
import 'package:thesis_shop/bloc_provider.dart';
|
|
import 'package:thesis_shop/models/product.dart';
|
|
import 'package:thesis_shop/widgets/number_picker.dart';
|
|
|
|
class ProductItem extends StatelessWidget {
|
|
final Product product;
|
|
const ProductItem({Key? key, required this.product}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cartBloc = AppState.of(context).blocProvider.cartBloc;
|
|
return ListTile(
|
|
title: Text('${product.title} (${product.priceAsString}€/Stück)'),
|
|
trailing: StreamBuilder<Cart>(
|
|
stream: cartBloc.cartStream,
|
|
initialData: cartBloc.cart,
|
|
builder: (context, snapshot) {
|
|
return NumberPicker(
|
|
value: snapshot.requireData[product] ?? 0,
|
|
onUp: () => cartBloc.quantityEventSink
|
|
.add(IncreaseQuantityEvent(product)),
|
|
onDown: () => cartBloc.quantityEventSink
|
|
.add(DecreaseQuantityEvent(product)),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|