在调用流取消时发出不必要的语句

flutter unnecessary statement on call to stream cancel

我有创建流并在处理期间取消流的 flutter 代码:

 @override
  void dispose()  {
    if (_playerSubscription != null) {
      _playerSubscription.cancel;
      _playerSubscription = null;
    }
    super.dispose();
  }

问题是,当我将代码提交到 pub.dev 时,静态分析器发出以下错误:

Avoid using unnecessary statements.

在线上发出错误:

_playerSubscription.cancel;

我检查了 async.dart 中的代码,它使用了与我完全相同的三行代码。

cancel()是一种方法。您需要像这样更改它:

  @override
  void dispose()  {
    if (_playerSubscription != null) {
      _playerSubscription.cancel();
      _playerSubscription = null;
    }
    super.dispose();
  }