我有一個 Flutter 應用程式Scaffold,我在其中放置了以下容器。這個容器包含計時器的分鐘和秒,以及兩個按鈕。Text當計時器處于活動狀態時,我試圖避免小部件重新居中。這似乎是因為Text當顯示不同的數字時小部件會改變大小。
我試圖Text用Expanded小部件包裝小部件,但它沒有解決問題。我該如何解決這個問題?
Container(
height: size.height * 0.40,
width: size.width * 0.80,
decoration: BoxDecoration(
color: Color(0xFFf4f6fa),
borderRadius: BorderRadius.circular(29.5)),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
"${f.format(_minutes)}:${f.format(_seconds)}",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 80,
color: Color(0xff7165E3),
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// STOP BUTTON
Container(
decoration: BoxDecoration(
color: Colors.grey[800],
shape: BoxShape.circle,
),
height: 90,
width: 90,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Colors.grey[800]),
shape: MaterialStateProperty.all(
CircleBorder()),
),
onPressed: () {
setState(() {
_stopTimer();
});
},
child: Container(
alignment: Alignment.center,
child: Text(
"Annulla",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
),
// START BUTTON
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
),
height: 90,
width: 90,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Color(0xff7165E3)),
shape: MaterialStateProperty.all(
CircleBorder()),
),
onPressed: () {
_startTimer();
},
child: Container(
alignment: Alignment.center,
child: Text(
"Avvia",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
),
],
),
],
),
),
uj5u.com熱心網友回復:
這是因為您使用的字體。

您使用的字體沒有負空間。嘗試使用一些調整了負空間的字體。I Roboto Mono 是一種具有負空間的字體。

在上圖中,字符占據相等的空間。
pubspec.yaml
google_fonts: ^2.1.0
運動螢屏.dart
Text(
"${f.format(_minutes)}:${f.format(_seconds)}",
textAlign: TextAlign.center,
style: GoogleFonts.robotoMono(
fontSize: 80.0,
color: const Color(0xff7165E3),
),
)
有關字體和負空間的更多資訊,請參閱
等寬字體

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/344148.html
