【发布时间】:2021-01-18 03:25:12
【问题描述】:
【问题讨论】:
标签: flutter user-interface colors textfield
【问题讨论】:
标签: flutter user-interface colors textfield
使用TextSpan 小部件,完美再现您的示例图像
RichText(
text: TextSpan(
// set the default style for the children TextSpans
style: Theme.of(context).textTheme.body1.copyWith(fontSize: 30),
children: [
TextSpan(
text: 'Hello, ',
),
TextSpan(
text: 'Wor',
style: TextStyle(
color: Colors.blue
)
),
TextSpan(
text: 'ld',
),
]
)
)
【讨论】:
在 TextField 中,这已经变得很困难,因为您不知道用户输入了什么。 如果您在谈论文本字段,则可以使用 RichText
RichText(
text: TextSpan(
// set the default style for the children TextSpans
style: Theme.of(context).textTheme.body1.copyWith(fontSize: 30),
children: [
TextSpan(
text: 'Styling ',
),
TextSpan(
text: 'text',
style: TextStyle(
color: Colors.blue
)
),
TextSpan(
text: ' in Flutter',
),
]
)
)
【讨论】:
我认为您正在寻找的是富文本编辑器或文本字段,我认为 Flutter 不支持开箱即用。我发现 pub 上有几个库最好是 zypher 或 creamy_field zypher 正在重新编写预发布可能需要注意这一点
【讨论】: