我的应用程序包含几页 . 在appbar中,我有一个自制的有状态小部件,其徽章显示新消息的数量 . 当我滑动以刷新数据时,如果更改徽章值,徽章将运行一个小动画 .

问题是徽章值来自范围模型 . 如何从作用域模型类运行动画 . 我试图让scoped模型类包含animationController以及一个函数 . 它适用于第一和第二屏幕 . 但是,当我再次导航回第一页并拉动刷新时 . 就像animationController处于糟糕状态一样 .

范围模型中的代码:

Function _runNotificationAnimation;
set runNotificationAnimation(Function fun) => _runNotificationAnimation = fun;

void _setNotificationCount(int count) {
  _notificationCount = count;

  if (count > 0 && _runNotificationAnimation != null) {
    _runNotificationAnimation();
 }
 notifyListeners();
}

运行动画的函数

runAnim() {
    setState(() {
      controller.reset();
      controller.forward(from: 0.0);
    });
  }

颤动的错误:

[VERBOSE-2:shell.cc(184)] Dart错误:未处理的异常:NoSuchMethodError:方法'stop'在null上调用 . Receiver:null尝试调用:stop(取消:true)0 Object.noSuchMethod(dart:core / runtime / libobject_patch.dart:50:5)1 AnimationController.stop(包:flutter / src / animation / animation_controller.dart:650: 13)2 AnimationController.value =(包:flutter / src / animation / animation_controller.dart:349:5)3 AnimationController.reset(包:flutter / src / animation / animation_controller.dart:370:5)4 NotificationIconState.runAnim( package:volvopenta / widgets / notificaton_icon.dart:38:16)5 SettingsModel._setNotificationCount(package:volvopenta / scoped-models / settings-model.dart:57:7)6 SettingsModel.updateAppData(package:volvopenta / scoped-models / settings-model.dart:185:5)7 MyMachines.build ...(包:volvopenta / pages / fleet.dart:83:27)8 <...>