flutter - TextField 导致“查找已停用小部件的祖先是不安全的。” 扑
问题描述
我有一个导致以下错误的 TextField。它仅在我开始在 TextField 中输入时触发。我尝试将 Sliverappbar 或 TextField 包装在 Builder 中,但遇到了同样的错误。
======== 小部件库捕获的异常====================================== ================== 在为 FocusManager 分派通知时引发以下断言:查找已停用小部件的祖先是不安全的。
此时小部件的元素树的状态不再稳定。
要在其 dispose() 方法中安全地引用小部件的祖先,请通过在小部件的 didChangeDependencies() 方法中调用dependOnInheritedWidgetOfExactType() 来保存对祖先的引用。
抛出异常时,这是堆栈:#0 Element._debugCheckStateIsActiveForAncestorLookup。(package:flutter/src/widgets/framework.dart:3906:9) #1 Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3920:6) #2 Element.dependOnInheritedWidgetOfExactType (package:flutter/src /widgets/framework.dart:3962:12) #3 MediaQuery.of (package:flutter/src/widgets/media_query.dart:814:38) #4 _InkResponseState._shouldShowFocus (package:flutter/src/material/ink_well.dart :925:44) ... FocusManager 发送通知是:FocusManager#23a1d primaryFocus: FocusNode#4875a([PRIMARY FOCUS]) primaryFocusCreator:
代码如下。
_showsearchfield
? _bottombarisVisible
? SliverAppBar(
backgroundColor: twhite,
leading: Container(),
flexibleSpace: FlexibleSpaceBar(
titlePadding: EdgeInsets.only(bottom: 3),
title: Container(
color: twhite,
//actual search box
child: Container(
height: screenheight*0.057,
margin: EdgeInsets.only(
left: screenwidth*0.041,
right: screenwidth*0.041,
top: screenheight*0.027,
bottom: screenheight*0.032
),
child: TextField(
style: MyTextStyle(16, tblack, FontWeight.w600),
controller: _mysearchwords,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 0, ),
borderRadius: BorderRadius.circular(5),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 0, ),
borderRadius: BorderRadius.circular(5),
),
suffixIcon: InkWell(
child:Icon(Icons.close,size: 20,color: tblack,),
splashColor: torangesplash,
onTap: _clearsearchtext,
),
contentPadding: EdgeInsets.only(left: 10),
hintText: 'Search',
hintStyle: TextStyle(fontSize: 16, color: Colors.black87,fontWeight: FontWeight.w400),
),
onSubmitted: (String value) async {
),
),
),
),
floating: false,
pinned: true,
)
: SliverToBoxAdapter(
child: Container(),
)
: SliverToBoxAdapter(
child: Container(),
),
解决方案
我有同样的问题,一个简单的 Flutter 热重启幸运地解决了我的问题
推荐阅读
- java - 在 Spring Data Rest v3.x 的 PersistentEntityResourceHandlerMethodArgumentResolver 中找不到自定义转换器
- c++ - 如何创建不同大小的子对象数组
- ios - 一旦我在颤动中更新了 Firebase 插件,我的应用程序就会抛出错误
- sql - 组合已知查询
- sql-server - 从字符串转换日期和/或时间时转换为日期然后转换失败
- reactjs - 运行 cypress 测试时 axios http 请求中缺少 cookie
- google-colaboratory - 使用pickle加载文件
- azure - AADSTS65001 invalid_grant 当所有权限都得到管理员同意时
- ios - Ionic App 在模拟的 iOS 手机中不起作用
- python - 如何删除重复的解决方案