From 59d7512f120475270144edf5c58cee8ca2427ca6 Mon Sep 17 00:00:00 2001 From: Lukas Mirbt Date: Fri, 26 Jul 2024 07:12:26 +0200 Subject: [PATCH] fix(flutter_login): fix flickering on login transition (#4210) Co-authored-by: Felix Angelov --- .../lib/login/view/login_form.dart | 6 +++--- .../test/login/view/login_form_test.dart | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/flutter_login/lib/login/view/login_form.dart b/examples/flutter_login/lib/login/view/login_form.dart index a2f67abcb4d..37803885c98 100644 --- a/examples/flutter_login/lib/login/view/login_form.dart +++ b/examples/flutter_login/lib/login/view/login_form.dart @@ -79,11 +79,11 @@ class _PasswordInput extends StatelessWidget { class _LoginButton extends StatelessWidget { @override Widget build(BuildContext context) { - final isInProgress = context.select( - (LoginBloc bloc) => bloc.state.status.isInProgress, + final isInProgressOrSuccess = context.select( + (LoginBloc bloc) => bloc.state.status.isInProgressOrSuccess, ); - if (isInProgress) return const CircularProgressIndicator(); + if (isInProgressOrSuccess) return const CircularProgressIndicator(); final isValid = context.select((LoginBloc bloc) => bloc.state.isValid); diff --git a/examples/flutter_login/test/login/view/login_form_test.dart b/examples/flutter_login/test/login/view/login_form_test.dart index 36bed5a16b9..244a5f50645 100644 --- a/examples/flutter_login/test/login/view/login_form_test.dart +++ b/examples/flutter_login/test/login/view/login_form_test.dart @@ -103,6 +103,25 @@ void main() { expect(find.byType(CircularProgressIndicator), findsOneWidget); }); + testWidgets('loading indicator is shown when status is submission success', + (tester) async { + when(() => loginBloc.state).thenReturn( + const LoginState(status: FormzSubmissionStatus.success), + ); + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: BlocProvider.value( + value: loginBloc, + child: LoginForm(), + ), + ), + ), + ); + expect(find.byType(ElevatedButton), findsNothing); + expect(find.byType(CircularProgressIndicator), findsOneWidget); + }); + testWidgets('continue button is enabled when status is validated', (tester) async { when(() => loginBloc.state).thenReturn(const LoginState(isValid: true));