row_bloc.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:flutter_bloc/flutter_bloc.dart';
  2. import 'package:freezed_annotation/freezed_annotation.dart';
  3. import 'dart:async';
  4. import 'data.dart';
  5. import 'row_service.dart';
  6. part 'row_bloc.freezed.dart';
  7. class RowBloc extends Bloc<RowEvent, RowState> {
  8. final RowService service;
  9. RowBloc({required GridRowData data, required this.service}) : super(RowState.initial(data)) {
  10. on<RowEvent>(
  11. (event, emit) async {
  12. await event.map(
  13. initial: (_InitialRow value) async {},
  14. createRow: (_CreateRow value) {},
  15. activeRow: (_ActiveRow value) {
  16. emit(state.copyWith(active: true));
  17. },
  18. disactiveRow: (_DisactiveRow value) {
  19. emit(state.copyWith(active: false));
  20. },
  21. );
  22. },
  23. );
  24. }
  25. @override
  26. Future<void> close() async {
  27. return super.close();
  28. }
  29. }
  30. @freezed
  31. abstract class RowEvent with _$RowEvent {
  32. const factory RowEvent.initial() = _InitialRow;
  33. const factory RowEvent.createRow() = _CreateRow;
  34. const factory RowEvent.activeRow() = _ActiveRow;
  35. const factory RowEvent.disactiveRow() = _DisactiveRow;
  36. }
  37. @freezed
  38. abstract class RowState with _$RowState {
  39. const factory RowState({
  40. required GridRowData data,
  41. required bool active,
  42. }) = _RowState;
  43. factory RowState.initial(GridRowData data) => RowState(data: data, active: false);
  44. }