flutter - 调整窗口大小时抽屉未正确关闭
问题描述
我有一个响应屏幕尺寸的网络应用程序。当屏幕类型是移动设备时,它会显示一个抽屉,而当屏幕类型是桌面设备时,它会显示一个通常的应用栏操作。当我缩小浏览器窗口以模仿移动屏幕类型时,就会出现问题。然后我打开抽屉。在不关闭抽屉的情况下,我将窗口最大化。但是会发生错误,并且应用栏上会出现一个后退按钮。如果我在最大化之前关闭我的抽屉,它工作正常。
以下是步骤。
后退按钮突然出现,这是我得到的错误代码。
======== Exception caught by widgets library =======================================================
The following assertion was thrown while finalizing the widget tree:
setState() or markNeedsBuild() called when widget tree was locked.
This Scaffold widget cannot be marked as needing to build because the framework is locked.
The widget on which setState() or markNeedsBuild() was called was: Scaffold
dependencies: [_ScaffoldMessengerScope, MediaQuery, _EffectiveTickerMode, UnmanagedRestorationScope, _InheritedTheme, _LocalizationsScope-[GlobalKey#69f10], Directionality]
state: ScaffoldState#5c645(tickers: tracking 2 tickers)
When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49 throw_
packages/flutter/src/widgets/framework.dart 4222:9 <fn>
packages/flutter/src/widgets/framework.dart 4231:14 markNeedsBuild
packages/flutter/src/widgets/framework.dart 1108:5 setState
packages/flutter/src/material/scaffold.dart 2142:5 [_drawerOpenedCallback]
...
====================================================================================================
======== Exception caught by animation library =====================================================
The following assertion was thrown while notifying listeners for AnimationController:
Assertion failed: file:///C:/Flutter/packages/flutter/lib/src/widgets/framework.dart:4188:12
_lifecycleState != _ElementLifecycle.defunct
is not true
When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49 throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed
packages/flutter/src/widgets/framework.dart 4188:49 markNeedsBuild
packages/flutter/src/widgets/framework.dart 1108:5 setState
packages/flutter/src/material/drawer.dart 356:5 [_animationChanged]
...
The AnimationController notifying listeners was: AnimationController#c00ed(⏮ 0.000; paused)
====================================================================================================
这是我的抽屉代码。
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
drawer: _getDrawer(context),
appBar: appBar(context),
body: SafeArea(
child: ListView(
children: [
NameTextWidgets(),
],
),
),
bottomNavigationBar: bottomAppBar(context),
);
}
//...
static Widget? _getDrawer(BuildContext context) {
return getDeviceType(context.mediaQuerySize) == DeviceScreenType.desktop
? null
: appBarActionDrawer();
}
//...
Drawer appBarActionDrawer() {
return Drawer(
child: ListView(
children: <Widget>[
DrawerHeader(
child: signatureText(),
),
] +
mobileNavigationButtons(),
),
);
}
这是我的应用条码
AppBar appBar(BuildContext context) {
AppBar ret;
var deviceType = getDeviceType(context.mediaQuerySize);
switch (deviceType) {
case DeviceScreenType.desktop:
ret = appBarDesktop();
break;
default:
ret = appBarMobile();
}
return ret;
}
//...
AppBar appBarDesktop() {
return AppBar(
elevation: 0.0,
title: signatureText(),
actions: desktopNavigationButtons()
..add(
themeSwitcher(),
),
);
}
AppBar appBarMobile() {
return AppBar(
elevation: 0.0,
actions: [
signatureText(),
],
);
}
如何删除该后退按钮并避免这些错误?
解决方案
推荐阅读
- javascript - 我想在 Vuex 之间共享价值观
- javascript - 如何访问每个数组中的元素?
- reactjs - 将表单值发送到服务器的正确方法 - React
- python-3.x - 显示特定月份的所有日期以获取数据
- python - Python网络爬取错误:将数据传输到数据库
- c++ - 在c ++中暂停执行的最快方法是什么
- python - 始终在框架中测量没有参考对象的对象大小
- vue.js - 我的 Nuxt Storyblok 项目返回错误
- matrix - 如何使用 MAGMA 和 NVIDIA GPU 卡而不是 CPU LAPACKE 来逆大矩阵
- sql - Sql查询日期之前和日期之间的总和