我想在 Flutter 中做到這一點:

我的代碼:
Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: const [
Text('Total', style: TextStyle( color: Color(0xFF68B762)),),
Text('Km', style: TextStyle( color: Color(0xFF68B762)),),
],),
const Text('612', style: TextStyle(fontSize: 30, fontFamily: SecondaryFontMedium, color: Color(0xFF68B762)),),
],),
結果:

uj5u.com熱心網友回復:
\n在“Total”和“Km”之間添加。像這樣使用,
Row(
children: [
Text('Total\nKm', textAlign: TextAlign.end, style: TextStyle(color: Color(0xFF68B762))),
Text('612',
style: TextStyle(
fontSize: 30,
fontFamily: SecondaryFontMedium,
color: Color(0xFF68B762))),
],
)
結果:

uj5u.com熱心網友回復:
我不知道錯誤是間距,還是左邊的字母沒有對齊,但我得到了這樣的東西:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 40, // change this
color: Colors.white,
child: FittedBox( // this is important
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: const [
Text(
'Total',
style: TextStyle(color: Color(0xFF68B762)),
),
Text(
'Km',
style: TextStyle(color: Color(0xFF68B762)),
),
],
),
),
),
Container(
height: 40, // change this
color: Colors.white,
child: const FittedBox( // this is important
child: Text(
'612',
style: TextStyle(
height: 1, // this is important
fontSize: 45,
color: Color(0xFF68B762),
),
),
),
),
],
)

我所做的是添加大小相等的兩個Container (例如 40),然后使用 Widget FittedBox使得當你降低容器的高度時,字母會適應并且你沒有問題......
現在在洗掉“填充”的第二個字母中添加了高度:1在TextStyle中,如果您可以閱讀更多內容會很好,所以您沒有問題,但基本上它可以與左邊的字母對齊.
嘗試編輯高度容器,你會看到
uj5u.com熱心網友回復:
如果你想讓它們靠得更近,你可以嘗試在樣式中設定一個高度Total。Km例如
Text('Total', style: TextStyle(height: 1, color: Color(0xFF68B762))),
Text('Km', style: TextStyle(height: 1, color: Color(0xFF68B762)),),
結果:

uj5u.com熱心網友回復:
嘗試這個,
return MaterialApp(
home: Scaffold(
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Total\nKm',
textAlign: TextAlign.right,
style: TextStyle(color: Color(0xFF68B762)),
),
SizedBox(
width: 5,
),
Text(
'612',
style: TextStyle(
fontSize: 30,
// fontFamily: SecondaryFontMedium,
color: Color(0xFF68B762)),
),
],
),
),
),
);
快樂編碼!
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/457139.html
