我有一个TextField,导致以下错误。 当我在TextField内部开始输入时,才会触发此错误。 我尝试将Sliverappbar或TextField包装在Builder中,但遇到相同的错误。
======== widgets library捕获的异常======================================= 在分派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:EditableText- [LabeledGlobalKey#ccd2a] ← UnmanagedRestorationScope ← RepaintBoundary ← _Decorator ← InputDecorator ← AnimatedBuilder ← _PointerListener ← Listener ← RawGestureDetector ← TextSelectionGestureDetector ← Semantics ← AnimatedBuilder ← IgnorePointer ← _RawMouseRegion ← MouseRegion ← TextField ← ConstrainedBox ← Padding ← Container ← ColoredBox ← ⋯
以下是代码。
======== widgets library捕获的异常======================================= 在分派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:EditableText- [LabeledGlobalKey#ccd2a] ← UnmanagedRestorationScope ← RepaintBoundary ← _Decorator ← InputDecorator ← AnimatedBuilder ← _PointerListener ← Listener ← RawGestureDetector ← TextSelectionGestureDetector ← Semantics ← AnimatedBuilder ← IgnorePointer ← _RawMouseRegion ← MouseRegion ← TextField ← ConstrainedBox ← Padding ← Container ← 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, ),
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(),
),