覆盖更新应该在颤振TickerMode中通知?



我正在尝试覆盖TickerMode(https://api.flutter.dev/flutter/widgets/TickerMode-class.html(中的updateShouldNotify。它在那里被列为一种方法,但是当我单击代码时,它实际上没有该方法。

我愿意:

class MyTickerMode extends TickerMode {
const MyTickerMode(
{Key key, @required bool enabled, Widget child})
: super(key: key, enabled: enabled, child: child);
@override
bool updateShouldNotify(TickerMode oldWidget) => false;
}

这将返回错误The method doesn't override an inherited method. #override_on_non_overriding_member

为什么? 我也尝试了updateShouldNotify(covariant TickerMode oldWidget)updateShouldNotify(_).

TickerMode中没有updateShouldNotify()方法。当您的类扩展InheritedWidget时,您需要重写此方法。您可以在ticker_provider文件中看到它在_EffectiveTickerMode中的覆盖。

最后,当您尝试覆盖可扩展类中不存在的方法时,会发生The method doesn't override an inherited method错误。

最新更新