[英]Flutter - How to show text and icon in one line in row?
我正在使用帶有三個子小部件的行小部件:文本圖標文本
我希望它們全部水平顯示在同一水平的單行中,如果文本增加則下降到新行。
我正在為 Row 小部件使用以下代碼,但最后一個 Text 小部件未正確對齊
文本放置應從“ Tap
”下方開始,並且“ on the right hand
”未對齊
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Tap ',
style: TextStyle(
fontSize: 17,
),
),
Icon(Icons.add),
Expanded(
child: Text(
'on the right hand corner to start a new chat.',
style: TextStyle(
fontSize: 17,
),
),
)
],
)
使用Text.rich
和WidgetSpan
將圖標放在文本中(內聯)
Text.rich(
TextSpan(
style: TextStyle(
fontSize: 17,
),
children: [
TextSpan(
text: 'Tap',
),
WidgetSpan(
child: Icon(Icons.add),
),
TextSpan(
text: 'on the right hand corner to start a new chat.',
)
],
),
)
Flutter 有 WidgetSpan() 來在 RichText() 中添加一個小部件。
RichText(
text: TextSpan(
children: [
TextSpan(
text: "Click ",
),
WidgetSpan(
child: Icon(Icons.add, size: 14),
),
TextSpan(
text: " to add",
),
],
),
)
上面的代碼將產生:
點擊 > 添加
您可以像對待普通小部件一樣對待 WidgetSpan 的子項。
你需要把 sinlein 線crossAxisAlignment: CrossAxisAlignment.start放在 Row 里面
Row (
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.add, size: 14),
Expanded(
child: Text("your multiline text "),
),
),
],
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.