Skip to content
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 @@ -73,7 +73,9 @@ class _ForgotPasswordViewState extends State<ForgotPasswordView> {
} on fba.FirebaseAuthException catch (e) {
exception = e;
} finally {
setState(() => isLoading = false);
if (mounted) {
setState(() => isLoading = false);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:firebase_auth/firebase_auth.dart' as fba;
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:firebase_ui_shared/firebase_ui_shared.dart';
Expand Down Expand Up @@ -95,5 +97,46 @@ void main() {
expect(find.byType(ErrorText), findsNothing);
verify(auth.sendPasswordResetEmail(email: 'delay@email.com')).called(1);
});

testWidgets(
"doesn't call setState if popped while sendPasswordResetEmail is pending",
(tester) async {
final completer = Completer<void>();
when(
auth.sendPasswordResetEmail(email: 'pending@email.com'),
).thenAnswer((_) => completer.future);

await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) => TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) =>
Scaffold(body: ForgotPasswordView(auth: auth)),
),
),
child: const Text('open'),
),
),
),
);
await tester.tap(find.text('open'));
await tester.pumpAndSettle();

await tester.enterText(find.byType(TextField), 'pending@email.com');
await tester.tap(find.byType(LoadingButton));
await tester.pump();

await tester.tap(find.text('Go back'));
await tester.pumpAndSettle();
expect(find.byType(ForgotPasswordView), findsNothing);

completer.complete();
await tester.pump();

expect(tester.takeException(), isNull);
},
);
});
}
Loading