gpt4 book ai didi

flutter - "How to create two text widgets in a row widget"

转载 作者:行者123 更新时间:2023-12-04 12:41:21 29 4
gpt4 key购买 nike

“我是flutter的初学者,我想在一行中显示两个文本。其中“hello”是第一个文本小部件,“world”是另一个文本小部件

我尝试用我的基本知识来做这件事,但我遇到了这些错误

Horizontal RenderFlex with multiple children has a null textDirection, so the layout order is undefined. 'package:flutter/src/rendering/flex.dart': Failed assertion: line 439 pos 18: 'textDirection != null'


    class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Row(
children: <Widget>[
Text("hello",textDirection: TextDirection.rtl,),
Text("world",textDirection: TextDirection.rtl,)
],
);
}
}

最佳答案

也许您想改用 RichText?

RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: 'hello', style: TextStyle(color: Colors.red)),
TextSpan(text: ' world', style: TextStyle(color: Colors.blue)),
],
),
)

关于flutter - "How to create two text widgets in a row widget",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58817872/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com