代码之家  ›  专栏  ›  技术社区  ›  Mary

覆盖更新是否应在Flatter TickerMode中通知?

  •  0
  • Mary  · 技术社区  · 6 年前

    我正试图超越 updateShouldNotify 在里面 TickerMode ( https://api.flutter.dev/flutter/widgets/TickerMode-class.html ).它被列为一种方法,但当我点击代码时,它实际上没有这种方法。

    我愿意:

    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(_) .

    0 回复  |  直到 6 年前
        1
  •  0
  •   Dmitry Shiryhalov    6 年前

    没有 updateShouldNotify() 方法 TickerMode 。当类扩展时,需要重写此方法 InheritedWidget .你可以在 _EffectiveTickerMode 在里面 ticker_provider

    最后 The method doesn't override an inherited method 尝试重写可扩展类中不存在的方法时出错。

    推荐文章