【发布时间】:2020-08-07 14:07:28
【问题描述】:
我有一个容器,其中有 2 个字段。 1 是百分比,另一个是简单文本。我需要的是我不想显示百分比容器,当我单击容器时,它只会显示百分比 3 秒然后消失,谁能告诉它怎么可能?
这是我的代码
int size = _questions.length;
void nextQuestion(){
if(index < size - 1)
setState(() {
index++;
});
print(index);
}
double percentage1Calculate(){
int wouldClick = int.parse(_questions[index]['wouldclick']);
int ratherClick = int.parse(_questions[index]['ratherclick']);
double percentage1 = wouldClick / (wouldClick + ratherClick) * 100;
return percentage1;
}
GestureDetector(
child: Container(
height: stackHeight * 0.5,
width: stackWidth,
color: Colors.blue,
child: Column(
children: <Widget>[
Container(
padding: const EdgeInsets.only(top: 10, right: 10),
height: stackHeight * 0.1,
color: Colors.blue,
width: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text('${percentage1Calculate().toStringAsFixed(0)}%',
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontFamily: 'NewsCycle',
),
),
],
)
),
Container(
color: Colors.blue,
height: stackHeight * 0.4,
width: double.infinity,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 20),
child: Text(
_questions[index]['would'],
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontFamily: 'NewsCycle',
),
),
),
],
)
),
],
),
),
),
在代码中,我在 GestureDetector 中包装了一个容器。在容器中我有 2 个容器。两者都显示文本。我需要的是当用户单击手势检测器时,第一个容器显示该值,并在 3 秒后隐藏。
【问题讨论】:
标签: flutter