我正在尝试在卡片小部件中实现通话按钮,
当我按下通话按钮时,我希望整个卡片背景变为蓝色(如选中),并在按下任何其他卡片时恢复正常,比如让通话按钮切换卡片选择,尝试使用setState 函数,但它不起作用,因为它仅在我点击整张卡片而不是其中的特定按钮时才会改变颜色。如何在按下通话按钮时选择整张卡并在按下任何其他卡时释放(从拨号器应用程序返回后)
这是我的代码:
_launchCaller() async {
const url = "tel:+972545522973";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
return Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Card(
margin: EdgeInsets.fromLTRB(20.0, 6.0, 20.0, 0.0),
color: Colors.brown[30],
child: ListTile(
isThreeLine: true,
title: Row(
children: <Widget> [
Container(
child:Text(widget.helpRequest.category.description) ,
alignment: Alignment.topLeft,
),
Spacer(),
Container(
child:Text(formatter.format(now)),
alignment: Alignment.topRight,
),
]
)
,
subtitle: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
GetUserName(widget.helpRequest.sender_id, DataBaseService().userInNeedCollection),
Text(widget.helpRequest.description),
]
)
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
onTap: (){
_launchCaller();
** Here i think I should add the code **
},
onLongPress: () => print("Long Press: Call"),
child: Padding(
padding: EdgeInsets.all(16.0),
child: Icon(Icons.call,
size: 20.0,
color: Colors.green,
)
),
),
],
),
),
),
);
我尝试使用的这个 setState 函数在我的情况下效果不佳(我正在更改 onTap 函数的状态):
void initState() {
super.initState();
color = Colors.transparent;
}