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:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
||||||
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
||||||
|
|
||||||
|
import '../../../../shared/components/molecules/locals/index.dart';
|
||||||
import 'index.dart';
|
import 'index.dart';
|
||||||
|
|
||||||
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||||
|
late StreamSubscription<bool> _completer;
|
||||||
|
|
||||||
HomeBloc() : super(HomeState()) {
|
HomeBloc() : super(HomeState()) {
|
||||||
on<HomeEvent>((event, emit) async {
|
on<HomeEvent>(_onHomeEvent);
|
||||||
final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? '';
|
_completer = LocalsRepositoryImpl.license.stream.listen((v) {
|
||||||
final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? '';
|
add(HomeEvent());
|
||||||
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,
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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 _buildDefaultLocalProfile(context, limitedFontSize);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return BlocBuilder<LocalProfileBloc, LocalProfileState>(
|
return BlocBuilder<LocalProfileBloc, LocalProfileState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
|
Loading…
Reference in New Issue