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.
41 lines
1.3 KiB
41 lines
1.3 KiB
import 'dart:async';
|
|
import 'package:bloc/bloc.dart';
|
|
import 'package:hadi_hoda_flutter/core/status/base_status.dart';
|
|
import 'package:hadi_hoda_flutter/features/sample/domain/entity/sample_entity.dart';
|
|
import 'package:hadi_hoda_flutter/features/sample/domain/usecases/get_sample_usecase.dart';
|
|
import 'package:hadi_hoda_flutter/features/sample/presentation/bloc/sample_event.dart';
|
|
import 'package:hadi_hoda_flutter/features/sample/presentation/bloc/sample_state.dart';
|
|
|
|
class SampleBloc extends Bloc<SampleEvent, SampleState> {
|
|
/// ------------constructor------------
|
|
SampleBloc(
|
|
this._getSampleUseCase,
|
|
) : super(const SampleState()) {
|
|
on<GetSampleEvent>(_getSampleEvent);
|
|
}
|
|
|
|
/// ------------UseCases------------
|
|
final GetSampleUseCase _getSampleUseCase;
|
|
|
|
/// ------------Variables------------
|
|
|
|
/// ------------Controllers------------
|
|
|
|
/// ------------Functions------------
|
|
|
|
/// ------------Api Calls------------
|
|
FutureOr<void> _getSampleEvent(event, emit) async {
|
|
await _getSampleUseCase(event.sampleParams).then(
|
|
(value) {
|
|
value.fold(
|
|
(data) {
|
|
emit(state.copyWith(getSampleStatus: BaseComplete<SampleEntity>(data)));
|
|
},
|
|
(error) {
|
|
emit(state.copyWith(getSampleStatus: BaseError(error.errorMessage)));
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|