mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-26 18:34:56 +00:00
separating folder
This commit is contained in:
@ -1,30 +0,0 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
|
||||
|
||||
class AddDeviceTypeModelBloc extends Cubit<List<SelectedProduct>> {
|
||||
AddDeviceTypeModelBloc(List<SelectedProduct> initialProducts)
|
||||
: super(initialProducts);
|
||||
|
||||
void updateProductCount(String productId, int count) {
|
||||
final existingProduct = state.firstWhere(
|
||||
(p) => p.productId == productId,
|
||||
orElse: () => SelectedProduct(productId: productId, count: 0),
|
||||
);
|
||||
|
||||
if (count > 0) {
|
||||
if (!state.contains(existingProduct)) {
|
||||
emit([...state, SelectedProduct(productId: productId, count: count)]);
|
||||
} else {
|
||||
final updatedList = state.map((p) {
|
||||
if (p.productId == productId) {
|
||||
return SelectedProduct(productId: p.productId, count: count);
|
||||
}
|
||||
return p;
|
||||
}).toList();
|
||||
emit(updatedList);
|
||||
}
|
||||
} else {
|
||||
emit(state.where((p) => p.productId != productId).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user