Business Login Flutter Apps
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.
 
 
 

39 line
1.2 KiB

  1. import 'dart:async';
  2. import 'package:bloc/bloc.dart';
  3. import 'package:equatable/equatable.dart';
  4. import '../../../Model/unit.dart';
  5. import '../../../Utils/db_helper.dart';
  6. part 'list_unit_event.dart';
  7. part 'list_unit_state.dart';
  8. class ListUnitBloc extends Bloc<ListUnitEvent, ListUnitState> {
  9. ListUnitBloc() : super(ListUnitInitial()) {
  10. on<ListUnitEvent>((event, emit) async {
  11. if(event is ListUnit){
  12. emit(ListUnitLoading());
  13. List<Unit> units = [];
  14. List<Blob?> blobs = [];
  15. try{
  16. await DBHelper.database.closeDb();
  17. if(event.search != null && event.search != ""){
  18. units = await DBHelper.database.searchAllUnits(event.search!.toUpperCase(),inserted: event.completed);
  19. }
  20. else{
  21. units = await DBHelper.database.getAllUnits(inserted: event.completed);
  22. }
  23. for (int i = 0;i<units.length;i++){
  24. blobs.add((units[i].mesin!=null)?await DBHelper.database.getThumbnail(units[i].mesin):null);
  25. }
  26. emit(ListUnitFinish(units: units,blobs: blobs));
  27. }
  28. catch(e){
  29. emit(ListUnitError(err: e.toString()));
  30. }
  31. }
  32. });
  33. }
  34. }