fix: homeBloc state managment
This commit is contained in:
parent
92a8986a7e
commit
d787f8e89c
|
@ -1,26 +1,38 @@
|
|||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
||||
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
||||
|
||||
import '../../../../shared/components/molecules/locals/index.dart';
|
||||
import 'index.dart';
|
||||
|
||||
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||
HomeBloc() : super(HomeState()) {
|
||||
on<HomeEvent>((event, emit) async {
|
||||
final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? '';
|
||||
final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? '';
|
||||
final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? '';
|
||||
final userName = (await StorageHelper().get(KeychainStorageKey.userName.value)) ?? '';
|
||||
final userEmail = (await StorageHelper().get(SecureStorageKey.email.value)) ?? '';
|
||||
late StreamSubscription<bool> _completer;
|
||||
|
||||
emit(state.copyWith(
|
||||
devUUID: devUUID,
|
||||
userUUID: userUUID,
|
||||
cliUUID: cliUUID,
|
||||
userName: userName,
|
||||
userEmail: userEmail,
|
||||
));
|
||||
HomeBloc() : super(HomeState()) {
|
||||
on<HomeEvent>(_onHomeEvent);
|
||||
_completer = LocalsRepositoryImpl.license.stream.listen((v) {
|
||||
add(HomeEvent());
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _onHomeEvent(HomeEvent event, Emitter<HomeState> emit) async {
|
||||
final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? '';
|
||||
final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? '';
|
||||
final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? '';
|
||||
final userName = (await StorageHelper().get(KeychainStorageKey.userName.value)) ?? '';
|
||||
final userEmail = (await StorageHelper().get(SecureStorageKey.email.value)) ?? '';
|
||||
|
||||
emit(state.copyWith(
|
||||
devUUID: devUUID,
|
||||
userUUID: userUUID,
|
||||
cliUUID: cliUUID,
|
||||
userName: userName,
|
||||
userEmail: userEmail,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,9 +52,7 @@ class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidge
|
|||
return _buildDefaultLocalProfile(context, limitedFontSize);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return BlocBuilder<LocalProfileBloc, LocalProfileState>(
|
||||
builder: (context, state) {
|
||||
|
|
Loading…
Reference in New Issue