前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【错误记录】Flutter 组件报错 ( No Directionality widget found. | RichText widgets require a Directionality )

【错误记录】Flutter 组件报错 ( No Directionality widget found. | RichText widgets require a Directionality )

作者头像
韩曙亮
发布2023-03-29 09:07:25
8730
发布2023-03-29 09:07:25
举报
文章被收录于专栏:韩曙亮的移动开发专栏

文章目录

一、报错信息


报错信息 :

代码语言:javascript
复制
Performing hot reload...
Syncing files to device Pixel 2...
Reloaded 0 libraries in 353ms.

======== Exception caught by widgets library =======================================================
The following assertion was thrown building Text("动画状态 : null"):
No Directionality widget found.

RichText widgets require a Directionality widget ancestor.

The specific widget that could not find a Directionality ancestor was: RichText
  softWrap: wrapping at box width
  maxLines: unlimited
  text: "动画状态 : null"
  dirty
The ownership chain for the affected widget is: "RichText ← Text ← Column ← Padding ← Container ← AnimationApp ← [root]"

Typically, the Directionality widget is introduced by the MaterialApp or WidgetsApp widget at the top of your application widget tree. It determines the ambient reading direction and is used, for example, to determine how to lay out text, how to interpret "start" and "end" values, and to resolve EdgeInsetsDirectional, AlignmentDirectional, and other *Directional objects.

The relevant error-causing widget was: 
  Text file:///D:/002_Project/002_Android_Learn/flutter_animation/lib/main.dart:118:11
When the exception was thrown, this was the stack: 
#0      debugCheckHasDirectionality.<anonymous closure> (package:flutter/src/widgets/debug.dart:272:7)
#1      debugCheckHasDirectionality (package:flutter/src/widgets/debug.dart:292:4)
#2      RichText.createRenderObject (package:flutter/src/widgets/basic.dart:5539:37)
#3      RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5423:28)
#4      MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6166:11)
...
====================================================================================================

======== Exception caught by widgets library =======================================================
No Directionality widget found.
The relevant error-causing widget was: 
  Text file:///D:/002_Project/002_Android_Learn/flutter_animation/lib/main.dart:120:11
====================================================================================================

======== Exception caught by rendering library =====================================================
A RenderFlex overflowed by 199358 pixels on the bottom.
The relevant error-causing widget was: 
  Column file:///D:/002_Project/002_Android_Learn/flutter_animation/lib/main.dart:96:14
====================================================================================================
在这里插入图片描述
在这里插入图片描述

报错组件 :

代码语言:javascript
复制
Text("动画状态 : $animationStatus"),
Text("动画值 : $animationValue"),

二、解决方案


Flutter 中 Text 组件需要设置文本方向 ;

修改后的代码为 :

代码语言:javascript
复制
Text("动画状态 : $animationStatus", textDirection: TextDirection.ltr,),
Text("动画值 : $animationValue", textDirection: TextDirection.ltr,),
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-03-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、报错信息
  • 二、解决方案
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档