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