Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logout button improvements - Fix padding on loading. Hide the button … #977

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import '../../base/common_ui_components/custom_app_bar.dart';
import '../../base/common_ui_components/update_button.dart';
import '../../base/theme/design_system.dart';
import '../../keys.dart';
import '../../l10n/l10n.dart';{{#has_authentication}}
import '../../lib_auth/blocs/user_account_bloc.dart';{{/has_authentication}}
import '../../l10n/l10n.dart';
import '../blocs/counter_bloc.dart';

class CounterPage extends StatelessWidget {
Expand Down Expand Up @@ -43,10 +42,7 @@ class CounterPage extends StatelessWidget {
AppErrorModalWidget<CounterBlocType>(
key: K.counterError,
errorState: (bloc) => bloc.states.errors,
),{{#has_authentication}}
AppErrorModalWidget<UserAccountBlocType>(
errorState: (bloc) => bloc.states.errors,
),{{/has_authentication}}
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import 'package:widget_toolkit_biometrics/widget_toolkit_biometrics.dart';{{/ena
import '../../app_extensions.dart';
import '../../base/common_ui_components/app_error_modal_widget.dart';
import '../../base/common_ui_components/app_divider.dart';
import '../../base/common_ui_components/app_list_tile.dart'; {{#enable_change_language}}
import '../../base/common_ui_components/app_list_tile.dart';{{#has_authentication}}
import '../../lib_auth/blocs/user_account_bloc.dart';{{/has_authentication}}{{#enable_change_language}}
import '../../lib_change_language/bloc/change_language_bloc.dart';
import '../../lib_change_language/extensions/language_model_extensions.dart';
import '../../lib_change_language/ui_components/language_picker_button.dart'; {{/enable_change_language}}{{#enable_pin_code}}
Expand Down Expand Up @@ -138,7 +139,7 @@ class ProfilePage extends StatelessWidget {
),
const AppDivider(),
{{/enable_pin_code}}
RxBlocBuilder<ProfileBlocType, Result<bool>>(
RxBlocBuilder<ProfileBlocType, Result<bool>>(
state: (bloc) => bloc.states.areNotificationsEnabled,
builder: (context, areNotificationsEnabled, bloc) =>
AppListTile(
Expand All @@ -161,8 +162,11 @@ class ProfilePage extends StatelessWidget {
),
AppErrorModalWidget<ProfileBlocType>(
errorState: (bloc) => bloc.states.errors,
),
RxBlocListener<ProfileBlocType, Result<bool>>(
),{{#has_authentication}}
AppErrorModalWidget<UserAccountBlocType>(
errorState: (bloc) => bloc.states.errors,
),{{/has_authentication}}
RxBlocListener<ProfileBlocType, Result<bool>>(
state: (bloc) => bloc.states.areNotificationsEnabled.skip(1),
condition: (previousState, currentState) =>
previousState is Result<bool>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ class LogoutActionButton extends StatelessWidget {
Widget build(BuildContext context) => Padding(
padding:
EdgeInsets.symmetric(horizontal: context.designSystem.spacing.m),
child: RxBlocBuilder<UserAccountBlocType, bool>(
state: (bloc) => bloc.states.isLoading,
builder: (context, loading, bloc) => loading.isLoading
? AppLoadingIndicator.textButtonValue(
context,
color: context.designSystem.colors.textButtonColor,
)
: IconButton(
icon: context.designSystem.icons.logoutIcon,
onPressed: () =>
context.read<UserAccountBlocType>().events.logout(),
),
child: RxBlocMultiBuilder2<UserAccountBlocType, bool, bool>(
state1: (bloc) => bloc.states.isLoading,
state2: (bloc) => bloc.states.loggedIn,
builder: (context, loading, loggedIn, bloc) => Visibility(
visible: loggedIn.data ?? false,
child: IconButton(
highlightColor: context.designSystem.colors.transparent,
icon: loading.isLoading
? AppLoadingIndicator.textButtonValue(
context,
color: context.designSystem.colors.textButtonColor,
)
: context.designSystem.icons.logoutIcon,
onPressed: loading.isLoading
? null
: context.read<UserAccountBlocType>().events.logout,
),
),
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,8 @@ class UserAccountBloc extends $UserAccountBloc {

_$logoutEvent
.throttleTime(const Duration(seconds: 1))
.exhaustMap((value) =>
_userAccountService.logout().asResultStream())
.exhaustMap((value) => _logOut().asResultStream())
.setResultStateHandler(this)
.whereSuccess()
.mapTo(false)
.emitAuthenticatedToCoordinator(_coordinatorBloc){{#enable_feature_otp}}
.emitOtpConfirmedToCoordinator(_coordinatorBloc){{/enable_feature_otp}}{{#enable_pin_code}}
.emitLoggedOutToCoordinator(_coordinatorBloc)
.emitPinCodeConfirmedToCoordinator(_coordinatorBloc){{/enable_pin_code}}
.doOnData((_) => _routerBloc.events.go(const LoginRoute()))
.listen(null)
.addTo(_compositeSubscription);
}
Expand All @@ -63,7 +55,17 @@ class UserAccountBloc extends $UserAccountBloc {
final AuthService _authService;
final RouterBlocType _routerBloc;

@override
Future<bool> _logOut() async {
await _userAccountService.logout();
_coordinatorBloc.events.authenticated(isAuthenticated: false);{{#enable_feature_otp}}
_coordinatorBloc.events.otpConfirmed(isOtpConfirmed: false);{{/enable_feature_otp}}{{#enable_pin_code}}
_coordinatorBloc.events.userLoggedOut();
_coordinatorBloc.events.pinCodeConfirmed(isPinCodeConfirmed: false);{{/enable_pin_code}}
_routerBloc.events.go(const LoginRoute());
return false;
}

@override
ConnectableStream<bool> _mapToLoggedInState() => Rx.merge([
_coordinatorBloc.states.isAuthenticated,
_authService.isAuthenticated().asStream(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ UserAccountBlocType userAccountBlocMockFactory({
.publishReplay(maxSize: 1)
..connect();

when(statesMock.loggedIn).thenAnswer(
(_) => Stream.value(loggedIn).publishReplay(maxSize: 1),
);
final loggedInState = Stream.value(loggedIn).publishReplay(maxSize: 1)
..connect();

when(statesMock.loggedIn).thenAnswer((_) => loggedInState);

when(statesMock.isLoading).thenAnswer((_) => loadingState);

when(statesMock.errors).thenAnswer(
(_) => error != null ? Stream.value(error) : const Stream.empty(),
);

when(statesMock.isLoading).thenAnswer((_) => loadingState);

return userAccountBloc;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,5 @@ extension CoordinatorBinderExtensions on Stream<bool> {
(isAuthenticated) => coordinator.events.authenticated(
isAuthenticated: isAuthenticated,
),
); {{#enable_pin_code}}

Stream<bool> emitLoggedOutToCoordinator(CoordinatorBlocType coordinator) =>
doOnData(
(isAuthenticated) => coordinator.events.userLoggedOut(),
);

Stream<bool> emitPinCodeConfirmedToCoordinator(
CoordinatorBlocType coordinator) =>
doOnData((isPinCodeConfirmed) {
return coordinator.events.pinCodeConfirmed(
isPinCodeConfirmed: isPinCodeConfirmed,
);
});{{/enable_pin_code}}
}

{{#enable_feature_otp}}
extension CoordinatorConfirmedBinderExtensions on Stream<bool> {
Stream<bool> emitOtpConfirmedToCoordinator(CoordinatorBlocType coordinator) =>
doOnData(
(isOtpConfirmed) => coordinator.events.otpConfirmed(
isOtpConfirmed: isOtpConfirmed,
),
);
}{{/enable_feature_otp}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class DesignSystemColors {

final Color updateIconAppBarColor;

final Color textButtonColor;
final Color textButtonColor;

final Color transparent = Colors.transparent;
{{#enable_social_logins}}
final Color appleBackground;

Expand Down
Loading