我有一个导致以下错误的TextField。只有当我开始在TextField中键入时,它才会被触发。我尝试在生成器中包装Sliverappbar或TextField,但遇到了同样的错误。
==========小部件库捕获到异常=======================================================在为FocusManager调度通知时引发了以下断言:查找停用的小部件的祖先是不安全的。
此时,小部件的元素树的状态不再稳定。
要在其dispose((方法中安全地引用小部件的祖先,请通过在小部件的didChangeDependencies((方法调用dependentOnInheritedWidgetOfExactType((来保存对祖先的引用。
当抛出异常时,这是堆栈:#0元素_debugCheckStateIsActiveForAncestorLookup。(包:flutter/src/widgets/framework。dart:3906:9(#1元素_debugCheckStateIsActiveForAncestorLookup(包:flutter/src/widgets/framework.dart:3920:6(#2 Element.dependOnInheritedWidgetOfExactType(包:flutter/src/widgets/framework。dart:3962:12(#3 MediaQuery.of(包:flutter/src/widgets/media_query.dart:814:38(#4 _确认响应状态_shouldShowFocus(包装:flutter/src/material/ink_well.dart:925:44(。。。FocusManager发送的通知是:FocusManager#23a1dprimaryFocus:FocusNode#4875a([PRIMARY FOCUS](primaryFocusCreator:EditableText-[Labeled全局密钥#ccd2a]←UnmanagedRestorityScope←重新绘制边界← _室内装修设计师←InputDecorator←动画生成器← _PointerListener←侦听器←RawGestureDetector←文本选择手势检测器←语义学←动画生成器←忽略指针← _RawMouseRegion←鼠标注册←文本字段←约束框←衬料←容器←彩色方框← ⋯
下面的代码。
_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热重启幸运地解决了我的问题