Skip to content

Commit

Permalink
fix(flutter_login): fix flickering on login transition (#4210)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Angelov <[email protected]>
  • Loading branch information
LukasMirbt and felangel authored Jul 26, 2024
1 parent 9f393a7 commit 59d7512
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/flutter_login/lib/login/view/login_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 19 additions & 0 deletions examples/flutter_login/test/login/view/login_form_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 59d7512

Please sign in to comment.