执行回调函数时未调用setState

时间:2019-07-12 04:10:56

标签: flutter dart

此代码段在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并在小部件上显示更改。有什么建议吗?

0 个答案:

没有答案