Fix local dev config and ALOTTTT OFF FLUTTER, im tired boss..
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../domain/repositories/sos_repository.dart';
|
||||
|
||||
enum SosPhase { idle, sending, sent, error }
|
||||
|
||||
class SosState {
|
||||
final SosPhase phase;
|
||||
final String? message;
|
||||
|
||||
const SosState({this.phase = SosPhase.idle, this.message});
|
||||
}
|
||||
|
||||
class SosCubit extends Cubit<SosState> {
|
||||
final SosRepository _repository;
|
||||
|
||||
SosCubit(this._repository) : super(const SosState());
|
||||
|
||||
Future<void> trigger({
|
||||
String triggerType = 'MANUAL',
|
||||
double? lat,
|
||||
double? lng,
|
||||
}) async {
|
||||
emit(const SosState(phase: SosPhase.sending));
|
||||
final result = await _repository.triggerSos(
|
||||
triggerType: triggerType,
|
||||
lat: lat,
|
||||
lng: lng,
|
||||
);
|
||||
result.fold(
|
||||
(failure) => emit(SosState(phase: SosPhase.error, message: failure.message)),
|
||||
(_) => emit(const SosState(
|
||||
phase: SosPhase.sent,
|
||||
message: 'SOS terkirim. Guardian sudah diberi tahu.',
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user