微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

TextField 导致“查找停用的小部件的祖先是不安全的”扑

如何解决TextField 导致“查找停用的小部件的祖先是不安全的”扑

我有一个导致以下错误的 TextField。它仅在我开​​始在 TextField 中输入时触发。我尝试将 Sliverappbar 或 TextField 包装在 Builder 中,但遇到了同样的错误

======== 小部件库捕获的异常 ================================== ====================== 为 FocusManager 分派通知时抛出以下断言: 查找已停用小部件的祖先是不安全的。

此时小部件的元素树的状态不再稳定。

要在其 dispose() 方法中安全地引用小部件的祖先,请通过在小部件的 didChangeDependencies() 方法调用 DependOnInheritedWidgetofExactType() 来保存对祖先的引用。

当抛出异常时,这是堆栈: #0 Element._debugCheckStateIsActiveForAncestorLookup。 (包: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 主要焦点:FocusNode#4875a([主要焦点]) primaryFocusCreator:EditableText- [LabeledGlobalKey#ccd2a]←←UnmanagedRestorationScope←RepaintBoundary←_Decorator←InputDecorator←AnimatedBuilder←_PointerListener监听←←RawGestureDetector←TextSelectionGestureDetector语义←←AnimatedBuilder←IgnorePointer←_RawMouseRegion←MouseRegion的TextField←←ConstrainedBox填充←←容器ColoredBox←⋯

下面的代码

_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,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(),

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。