fix: prevent setState after pop with _popped guard, remove snackbar from compose to prevent scaffold corruption on Android
This commit is contained in:
parent
1d05300f17
commit
d6204db5c4
|
|
@ -39,6 +39,7 @@ class _ComposeScreenState extends ConsumerState<ComposeScreen> {
|
|||
|
||||
bool _isLoading = false;
|
||||
bool _isUploadingImage = false;
|
||||
bool _popped = false;
|
||||
String? _errorMessage;
|
||||
String? _blockedMessage;
|
||||
final int _maxCharacters = 500;
|
||||
|
|
@ -458,32 +459,32 @@ class _ComposeScreenState extends ConsumerState<ComposeScreen> {
|
|||
isNsfw: _isNsfw,
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
if (mounted && !_popped) {
|
||||
_popped = true;
|
||||
ref.read(feedRefreshProvider.notifier).increment();
|
||||
// Show snackbar BEFORE pop — after pop the context is defunct on web
|
||||
sojornSnackbar.showSuccess(
|
||||
context: context,
|
||||
message: 'Post published',
|
||||
);
|
||||
if (mounted) Navigator.of(context).pop(true);
|
||||
Navigator.of(context).pop(true);
|
||||
return; // Skip finally setState — widget is being disposed
|
||||
}
|
||||
} on ToneCheckException {
|
||||
setState(() {
|
||||
_errorMessage =
|
||||
'Content verification temporarily unavailable. Please try again.';
|
||||
});
|
||||
if (mounted && !_popped) {
|
||||
setState(() {
|
||||
_errorMessage =
|
||||
'Content verification temporarily unavailable. Please try again.';
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted || _popped) return;
|
||||
final msg = e.toString().replaceAll('Exception: ', '');
|
||||
// Server-side blocklist catch (422 with blocked content message)
|
||||
if (msg.contains("isn't allowed on Sojorn") || msg.contains('not allowed')) {
|
||||
if (mounted) setState(() => _blockedMessage = msg);
|
||||
setState(() => _blockedMessage = msg);
|
||||
} else {
|
||||
setState(() {
|
||||
_errorMessage = msg;
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
if (mounted && !_popped) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue