此代码段在initState()上调用。
void _countDown() async {
await Future.delayed(Duration(seconds: 5));
if (mounted) {
setState(() {
driverArrived = true;
});
widget.onDriverReached();
}
}
onDriverReached是一个VoidCallback
class ClientDetail extends StatefulWidget {
final VoidCallback onDriverReached;
ClientDetail({this.onDriverReached});
@override
_ClientDetailState createState() => _ClientDetailState();
}
回调函数执行完美,但从未调用setState。如果我删除回调,则会调用setState并在小部件上显示更改。有什么建议吗?