【发布时间】:2021-12-12 05:17:15
【问题描述】:
我有一个带有Scaffold 的颤振应用程序,我在其中放置了以下容器。
此容器包含计时器的分钟和秒,以及两个按钮。
我试图避免Text 小部件在计时器处于活动状态时重新居中。这似乎是因为 Text 小部件在显示不同的数字时会改变大小。
我尝试用Expanded 小部件包装Text 小部件,但它没有解决问题。我该如何解决这个问题?
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,
),
),
),
),
),
],
),
],
),
),
【问题讨论】:
-
你在 f.format(_minutes) 函数中有什么?
-
@Vettiyanakan 我正在使用 intl 包来显示两位数,我有这个
var f = NumberFormat("00");。如果您需要更多信息,请随时询问 -
你能发布完整的页面代码吗?至少声明和那些函数。
-
请查看此 FB 帖子和 cmets,facebook.com/vettiyankan.vm/posts/900287173767708:7
-
@Vettiyanakan 这里有完整页面代码:pastebin.com/fj2PyK8n
标签: android flutter dart user-interface timer