feat(auth): 登录异常改为居中弹窗
This commit is contained in:
1 parent
9b78e43702
commit
b0002abf82
14 files changed
+436
-10
No files matched your search
@@ -12,6 +12,7 @@ import '../../core/platform/keyboard_inset.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/theme/app_dimens.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../core/widgets/centered_error_dialog.dart';
|
||||
import '../../core/widgets/subpage_header.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import 'auth_logic.dart';
|
||||
@@ -227,6 +228,7 @@ class _AuthPageState extends State<AuthPage> {
|
||||
_logic.errorMessage = null;
|
||||
});
|
||||
final auth = context.read<AuthController>();
|
||||
String? failureMessage;
|
||||
try {
|
||||
if (_logic.signUpMode) {
|
||||
await auth.register(
|
||||
@@ -242,14 +244,18 @@ class _AuthPageState extends State<AuthPage> {
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).maybePop();
|
||||
} on ApiException catch (error) {
|
||||
if (!mounted) return;
|
||||
setState(() => _logic.errorMessage = error.message);
|
||||
failureMessage = error.message;
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
setState(() => _logic.errorMessage = l10n.authNetworkError);
|
||||
failureMessage = l10n.authNetworkError;
|
||||
} finally {
|
||||
if (mounted) setState(() => _logic.busy = false);
|
||||
}
|
||||
if (!mounted || failureMessage == null) return;
|
||||
await showCenteredErrorDialog(
|
||||
context,
|
||||
title: _logic.signUpMode ? l10n.authRegisterFailed : l10n.authLoginFailed,
|
||||
message: failureMessage,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -11,6 +11,7 @@ import '../../core/data/services/auth_controller.dart';
|
||||
import '../../core/platform/haptics.dart';
|
||||
import '../../core/platform/keyboard_inset.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/widgets/centered_error_dialog.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
const double _fieldHeight = 52;
|
||||
@@ -164,6 +165,7 @@ class _PhoneAuthSheetState extends State<PhoneAuthSheet> {
|
||||
});
|
||||
final haptics = context.read<Haptics>();
|
||||
final auth = context.read<AuthController>();
|
||||
String? failureMessage;
|
||||
await haptics.lightImpact();
|
||||
try {
|
||||
await auth.sendOtp(
|
||||
@@ -173,16 +175,20 @@ class _PhoneAuthSheetState extends State<PhoneAuthSheet> {
|
||||
if (!mounted) return;
|
||||
_startCountdown();
|
||||
setState(() => _error = null);
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(l10n.authCodeSent)));
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(l10n.authCodeSent)));
|
||||
_codeFocus.requestFocus();
|
||||
} on ApiException catch (error) {
|
||||
if (mounted) setState(() => _error = error.message);
|
||||
failureMessage = error.message;
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _error = l10n.authNetworkError);
|
||||
failureMessage = l10n.authNetworkError;
|
||||
} finally {
|
||||
if (mounted) setState(() => _sending = false);
|
||||
}
|
||||
if (mounted && failureMessage != null) {
|
||||
await _showFailure(failureMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void _startCountdown() {
|
||||
@@ -212,6 +218,7 @@ class _PhoneAuthSheetState extends State<PhoneAuthSheet> {
|
||||
});
|
||||
final haptics = context.read<Haptics>();
|
||||
final auth = context.read<AuthController>();
|
||||
String? failureMessage;
|
||||
await haptics.lightImpact();
|
||||
try {
|
||||
if (_signUp) {
|
||||
@@ -221,12 +228,24 @@ class _PhoneAuthSheetState extends State<PhoneAuthSheet> {
|
||||
}
|
||||
if (mounted) Navigator.of(context).pop(true);
|
||||
} on ApiException catch (error) {
|
||||
if (mounted) setState(() => _error = error.message);
|
||||
failureMessage = error.message;
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _error = l10n.authNetworkError);
|
||||
failureMessage = l10n.authNetworkError;
|
||||
} finally {
|
||||
if (mounted) setState(() => _submitting = false);
|
||||
}
|
||||
if (mounted && failureMessage != null) {
|
||||
await _showFailure(failureMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showFailure(String message) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return showCenteredErrorDialog(
|
||||
context,
|
||||
title: _signUp ? l10n.authRegisterFailed : l10n.authLoginFailed,
|
||||
message: message,
|
||||
);
|
||||
}
|
||||
|
||||
void _switchMode() {
|
||||
|
||||
Reference in new issue
Block a user