我想在文本小部件中显示一个图标。我该怎么做呢 ?
以下代码仅显示IconData
Text("Click ${Icons.add} to add");
最佳答案
Flutter 有 WidgetSpan()
在 RichText()
中添加一个小部件。
使用示例:
RichText(
text: TextSpan(
children: [
TextSpan(
text: "Click ",
),
WidgetSpan(
child: Icon(Icons.add, size: 14),
),
TextSpan(
text: " to add",
),
],
),
)
上面的代码会产生:
您可以将 WidgetSpan
的子级视为通常的小部件。
https://stackoverflow.com/questions/56840994/
相关文章:
dart - CustomScrollView 中的 Flutter 固定按钮
dart - 有没有办法在 Flutter 的多个 PageRoutes 中使用 Inherited
dart - const 在 Flutter 中定义 EdgeInsets 中的作用
dart - 如何使用 Flutter 在 Android 中显示 iOS/cupertino 警报
dart - NumberFormat 未找到 flutter
mobile - Dart:流与 ValueNotifiers
android - 如何在 Flutter 中动态附加到 Column 小部件的子级
firebase - 使用 FirebaseAuth 、 Firestore 和 Google 登录