49 lines
1.5 KiB
Dart
49 lines
1.5 KiB
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'discount_event.dart';
|
|
import 'discount_state.dart';
|
|
|
|
class DiscountBloc extends Bloc<DiscountEvent, DiscountState> {
|
|
DiscountBloc() : super(const DiscountState()) {
|
|
on<ProductImageAdded>((event, emit) {
|
|
List<String> updatedImages = List.from(state.productImages);
|
|
if (updatedImages.length > event.index) {
|
|
updatedImages[event.index] = event.imagePath;
|
|
} else {
|
|
updatedImages.add(event.imagePath);
|
|
}
|
|
emit(state.copyWith(productImages: updatedImages));
|
|
});
|
|
|
|
on<ProductNameChanged>((event, emit) {
|
|
emit(state.copyWith(productName: event.name));
|
|
});
|
|
|
|
on<DiscountTypeChanged>((event, emit) {
|
|
emit(state.copyWith(discountType: event.type));
|
|
});
|
|
|
|
on<DescriptionChanged>((event, emit) {
|
|
emit(state.copyWith(description: event.description));
|
|
});
|
|
|
|
on<ValidityDateChanged>((event, emit) {
|
|
emit(state.copyWith(startDate: event.startDate, endDate: event.endDate));
|
|
});
|
|
|
|
on<TimeRangeChanged>((event, emit) {
|
|
emit(state.copyWith(startTime: event.startTime, endTime: event.endTime));
|
|
});
|
|
|
|
on<PriceChanged>((event, emit) {
|
|
emit(state.copyWith(price: event.price));
|
|
});
|
|
|
|
on<DiscountedPriceChanged>((event, emit) {
|
|
emit(state.copyWith(discountedPrice: event.price));
|
|
});
|
|
|
|
on<NotificationRadiusChanged>((event, emit) {
|
|
emit(state.copyWith(notificationRadius: event.radius));
|
|
});
|
|
}
|
|
} |