geo-smart-app/lib/bloc/setting/setting_bloc.dart

37 lines
1.2 KiB
Dart
Raw Normal View History

2020-07-28 18:11:47 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:geosmart/bloc/authentication/authentication.dart';
import 'package:geosmart/bloc/setting/setting_event.dart';
import 'package:geosmart/bloc/setting/setting_state.dart';
import 'package:geosmart/model/setting.dart';
import 'package:geosmart/service/setting_service.dart';
import 'package:geosmart/service/unique_id_service.dart';
class SettingBloc extends Bloc<SettingEvent, SettingState> {
final AuthenticationBloc authenticationBloc;
2024-12-25 05:37:16 +00:00
SettingBloc({required this.authenticationBloc}) : super(SettingInitial()) {
on<SettingSet>((event, emit) async {
emit(SettingProgress());
2020-07-28 18:11:47 +00:00
if (event.host != null && event.host != "") {
try {
final s = await UniqueIDService().getUniqueID(
event.host,
authenticationBloc.dio,
);
SettingService().setSetting(SettingModel(
event.host,
s.id,
));
2024-12-25 05:37:16 +00:00
emit(SettingSuccess());
2020-07-28 18:11:47 +00:00
} catch (_) {
2024-12-25 05:37:16 +00:00
emit(SettingFailed(
2020-07-28 18:11:47 +00:00
message: "Make sure your host is correct and alive.",
2024-12-25 05:37:16 +00:00
));
2020-07-28 18:11:47 +00:00
}
} else {
2024-12-25 05:37:16 +00:00
emit(SettingFailed(message: "Host cannot null or empty."));
2020-07-28 18:11:47 +00:00
}
2024-12-25 05:37:16 +00:00
});
2020-07-28 18:11:47 +00:00
}
}