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,23 +110,22 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
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

View File

@@ -54,17 +54,17 @@ class _WhisperDetailPageState extends State<WhisperDetailPage>
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;
});
}
});
});