我完全陌生,我的第一步已经引起了我无法自行解决或搜索此网站的错误。
我想创建一个按钮,但据我了解缺少方向性。唯一需要textDirection的窗口小部件是文本窗口小部件,但是它具有ist,那么这怎么了? Full Start也已经尝试了多次,包括。新的模拟器。
这是我的代码:
import 'package:flutter/material.dart';
void main(){
runApp(
new MyStatefullWidget()
) ;
}
class MyStatefullWidget extends StatefulWidget {
@override
_MyStatefullWidgetState createState() => _MyStatefullWidgetState();
}
class _MyStatefullWidgetState extends State<MyStatefullWidget> {
@override
Widget build(BuildContext context) {
return Container(
color:Colors.red,
child: Center(
child: RaisedButton(
child: Text("klick mich", textDirection: TextDirection.ltr),
onPressed: (){
print("Hi");
},
),
),
);
}
}
这是错误消息:
I/flutter ( 4763): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 4763): The following assertion was thrown building InkWell(gestures: [tap], clipped to BoxShape.rectangle,
I/flutter ( 4763): dirty, state: _InkResponseState<InkResponse>#43345):
I/flutter ( 4763): No Directionality widget found.
I/flutter ( 4763): InkWell widgets require a Directionality widget ancestor.
I/flutter ( 4763): The specific widget that could not find a Directionality ancestor was:
I/flutter ( 4763): InkWell(gestures: [tap], clipped to BoxShape.rectangle)
I/flutter ( 4763): The ownership chain for the affected widget is:
I/flutter ( 4763): InkWell ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#64251 ink
I/flutter ( 4763): renderer] ← NotificationListener<LayoutChangedNotification> ← CustomPaint ← _ShapeBorderPaint ←
I/flutter ( 4763): PhysicalShape ← _MaterialInterior ← Material ← ⋯
I/flutter ( 4763): Typically, the Directionality widget is introduced by the MaterialApp or WidgetsApp widget at the
I/flutter ( 4763): top of your application widget tree. It determines the ambient reading direction and is used, for
I/flutter ( 4763): example, to determine how to lay out text, how to interpret "start" and "end" values, and to resolve
I/flutter ( 4763): EdgeInsetsDirectional, AlignmentDirectional, and other *Directional objects.
I/flutter ( 4763):
I/flutter ( 4763): When the exception was thrown, this was the stack:
I/flutter ( 4763): #0 debugCheckHasDirectionality.<anonymous closure> (package:flutter/src/widgets/debug.dart:241:7)
I/flutter ( 4763): #1 debugCheckHasDirectionality (package:flutter/src/widgets/debug.dart:257:4)
I/flutter ( 4763): #2 InkResponse.debugCheckContext (package:flutter/src/material/ink_well.dart:376:12)
I/flutter ( 4763): #3 _InkResponseState.build (package:flutter/src/material/ink_well.dart:554:19)
I/flutter ( 4763): #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:3809:27)
I/flutter ( 4763): #5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15)
I/flutter ( 4763): #6 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter ( 4763): #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #13 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #18 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #19 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #20 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #21 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter ( 4763): #22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter ( 4763): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #30 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #31 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #33 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #34 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter ( 4763): #35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #38 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #39 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #40 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #41 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #42 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #43 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter ( 4763): #44 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #45 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #46 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #47 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #48 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #49 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter ( 4763): #50 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #51 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #52 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #53 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #54 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #55 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #56 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter ( 4763): #57 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #58 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #59 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #60 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter ( 4763): #61 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #62 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #63 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter ( 4763): #64 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #65 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #66 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter ( 4763): #67 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #68 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #69 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #70 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #71 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #72 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter ( 4763): #73 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #74 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #75 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #76 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #77 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #78 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #79 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #80 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #81 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #82 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter ( 4763): #83 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #84 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #85 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter ( 4763): #86 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #87 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #88 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #89 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #90 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #91 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #92 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #93 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #94 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter ( 4763): #95 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter ( 4763): #96 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter ( 4763): #97 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter ( 4763): #98 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter ( 4763): #99 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter ( 4763): #100 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter ( 4763): #101 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:909:16)
I/flutter ( 4763): #102 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:880:5)
I/flutter ( 4763): #103 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:826:17)
I/flutter ( 4763): #104 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2266:19)
I/flutter ( 4763): #105 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:825:13)
I/flutter ( 4763): #106 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:712:7)
I/flutter ( 4763): #107 runApp (package:flutter/src/widgets/binding.dart:756:7)
I/flutter ( 4763): #108 main (package:flutter_app/main.dart:4:3)
I/flutter ( 4763): #109 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289:19)
I/flutter ( 4763): #110 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
I/flutter ( 4763): ════════════════════════════════════════════════════════════════════════════════════════════════════
答案 0 :(得分:1)
您必须在容器之前添加一个MaterialApp
小部件,像这样:
class _MyStatefullWidgetState extends State<MyStatefullWidget> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Container(
color: Colors.red,
child: Center(
child: RaisedButton(
child: Text("klick mich", textDirection: TextDirection.ltr),
onPressed: () {
print("Hi");
},
),
),
),
);
}
}
答案 1 :(得分:0)
我也遇到了同样的错误,并添加了更多信息,可以通过查看错误消息来解决问题,但简短的是,我们可以在页面顶部使用MaterialApp
或WidgetsApp
小部件树(如上所示):
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
在InkWell(手势:[tap],裁剪到BoxShape.rectangle, 肮脏的,状态:_InkResponseState#1b61e):
未找到方向性小部件。
Inkell小部件需要Directionality小部件祖先。
找不到方向性祖先的特定小部件为: 千瓦数
受影响的小部件的所有权链为:“ InkWell←DefaultTextStyle← AnimatedDefaultTextStyle←_InkFeatures- [GlobalKey#3bd76墨水渲染器]← NotificationListener←CustomPaint←_ShapeBorderPaint←PhysicalShape ←_MaterialInterior←材质←⋯“
通常,定向性小部件由MaterialApp或WidgetsApp小部件在 应用程序小部件树的顶部。它确定环境读取方向,并用于 例如,确定如何布置文本,如何解释“开始”和“结束”值以及解决 EdgeInsetsDirectional,AlignmentDirectional和其他* Direction对象。