fix: mounted为false的情况

This commit is contained in:
orz12
2024-04-04 10:48:46 +08:00
parent d714d7c1b1
commit 88786d83c8
2 changed files with 22 additions and 23 deletions

View File

@@ -110,24 +110,23 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
void didChangeMetrics() { void didChangeMetrics() {
super.didChangeMetrics(); super.didChangeMetrics();
final String routePath = Get.currentRoute; final String routePath = Get.currentRoute;
if (mounted){ if (!mounted) return;
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
// 键盘高度 // 键盘高度
final viewInsets = EdgeInsets.fromViewPadding( final viewInsets = EdgeInsets.fromViewPadding(
View.of(context).viewInsets, View.of(context).devicePixelRatio); View.of(context).viewInsets, View.of(context).devicePixelRatio);
_debouncer.run(() { _debouncer.run(() {
if (mounted) { if (!mounted) return;
if (keyboardHeight == 0 && emoteHeight == 0) { if (keyboardHeight == 0 && emoteHeight == 0) {
setState(() { setState(() {
emoteHeight = keyboardHeight = emoteHeight = keyboardHeight =
keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight; keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight;
}); });
} }
}
}); });
}); });
} }
}
@override @override
void dispose() { void dispose() {

View File

@@ -54,18 +54,18 @@ class _WhisperDetailPageState extends State<WhisperDetailPage>
final String routePath = Get.currentRoute; final String routePath = Get.currentRoute;
if (mounted && routePath.startsWith('/whisper_detail')) { if (mounted && routePath.startsWith('/whisper_detail')) {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
// 键盘高度 // 键盘高度
final viewInsets = EdgeInsets.fromViewPadding( final viewInsets = EdgeInsets.fromViewPadding(
View.of(context).viewInsets, View.of(context).devicePixelRatio); View.of(context).viewInsets, View.of(context).devicePixelRatio);
_debouncer.run(() { _debouncer.run(() {
if (mounted) { if (!mounted) return;
if (keyboardHeight == 0) { if (keyboardHeight == 0) {
setState(() { setState(() {
emoteHeight = keyboardHeight = emoteHeight = keyboardHeight =
keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight; keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight;
}); });
} }
}
}); });
}); });
} }