From 88786d83c839dc91a54444135679549b3be45496 Mon Sep 17 00:00:00 2001 From: orz12 Date: Thu, 4 Apr 2024 10:48:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20mounted=E4=B8=BAfalse=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/video/detail/reply_new/view.dart | 31 +++++++++++----------- lib/pages/whisper_detail/view.dart | 14 +++++----- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/pages/video/detail/reply_new/view.dart b/lib/pages/video/detail/reply_new/view.dart index 26646441..de25e3c9 100644 --- a/lib/pages/video/detail/reply_new/view.dart +++ b/lib/pages/video/detail/reply_new/view.dart @@ -110,23 +110,22 @@ class _VideoReplyNewDialogState extends State void didChangeMetrics() { super.didChangeMetrics(); final String routePath = Get.currentRoute; - if (mounted){ - WidgetsBinding.instance.addPostFrameCallback((_) { - // 键盘高度 - final viewInsets = EdgeInsets.fromViewPadding( - View.of(context).viewInsets, View.of(context).devicePixelRatio); - _debouncer.run(() { - if (mounted) { - if (keyboardHeight == 0 && emoteHeight == 0) { - setState(() { - emoteHeight = keyboardHeight = - keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight; - }); - } - } - }); + if (!mounted) return; + WidgetsBinding.instance.addPostFrameCallback((_) { + if (!mounted) return; + // 键盘高度 + final viewInsets = EdgeInsets.fromViewPadding( + View.of(context).viewInsets, View.of(context).devicePixelRatio); + _debouncer.run(() { + if (!mounted) return; + if (keyboardHeight == 0 && emoteHeight == 0) { + setState(() { + emoteHeight = keyboardHeight = + keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight; + }); + } }); - } + }); } @override diff --git a/lib/pages/whisper_detail/view.dart b/lib/pages/whisper_detail/view.dart index cb55c3e7..ce701ff4 100644 --- a/lib/pages/whisper_detail/view.dart +++ b/lib/pages/whisper_detail/view.dart @@ -54,17 +54,17 @@ class _WhisperDetailPageState extends State final String routePath = Get.currentRoute; if (mounted && routePath.startsWith('/whisper_detail')) { WidgetsBinding.instance.addPostFrameCallback((_) { + if (!mounted) return; // 键盘高度 final viewInsets = EdgeInsets.fromViewPadding( View.of(context).viewInsets, View.of(context).devicePixelRatio); _debouncer.run(() { - if (mounted) { - if (keyboardHeight == 0) { - setState(() { - emoteHeight = keyboardHeight = - keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight; - }); - } + if (!mounted) return; + if (keyboardHeight == 0) { + setState(() { + emoteHeight = keyboardHeight = + keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight; + }); } }); });