本文主要是介绍No Directionality widget found. RichText widgets require a Directionality widget a Directio.......,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- 报错
flutter: No Directionality widget found.
flutter: RichText widgets require a Directionality widget ancestor.
flutter: The specific widget that could not find a Directionality ancestor was:
flutter: RichText
- 使用text组件时,没有设置文字对齐方式,导致的报错,一般情况下App的最外层都是Scaffold组件包裹,因此Text有默认的样式,如果Text组件的父组件没有Scaffold,需要设置样式。
- 解决:textDirection: TextDirection.ltr
import 'package:flutter/material.dart';void main()=> runApp(MyApp());class MyApp extends StatelessWidget {@override// build 返回一个Widget 一个类就是widgetWidget build(BuildContext context) {return Container(child: Text('123',textDirection: TextDirection.ltr),);}
}
这篇关于No Directionality widget found. RichText widgets require a Directionality widget a Directio.......的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!