Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振管理课堂外的动画控制器_Flutter_Flutter Animation - Fatal编程技术网

Flutter 颤振管理课堂外的动画控制器

Flutter 颤振管理课堂外的动画控制器,flutter,flutter-animation,Flutter,Flutter Animation,这是我在课堂上使用的简单动画 controller = AnimationController(vsync: this, duration: Duration(milliseconds: 200)); offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, -1.0)).animate(controller); controller.forward(); 源代码 class NotificationBar exten

这是我在课堂上使用的简单动画

controller = AnimationController(vsync: this, duration: Duration(milliseconds: 200));

offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, -1.0)).animate(controller);
controller.forward();
源代码

class NotificationBar extends StatefulWidget {
  final Widget contentWidget;
  final Widget barWidget;

  NotificationBar({@required this.contentWidget, @required this.barWidget});

  @override
  State<StatefulWidget> createState() => NotificationBarState();
}

class NotificationBarState extends State<NotificationBar>  with SingleTickerProviderStateMixin {
  AnimationController controller;
  Animation<Offset> offset;

  @override
  void initState() {
    super.initState();

    controller = AnimationController(vsync: this, duration: Duration(milliseconds: 200));
    // offset = Tween<Offset>(begin: Offset.zero, end: Offset(1.0, 0.0)).animate(controller); from right
    offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, -1.0)).animate(controller);
    controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
      ),
    );
  }
}
class NotificationBar扩展StatefulWidget{
最终小部件内容小部件;
最终小部件;
NotificationBar({@required this.contentWidget,@required this.barWidget});
@凌驾
State createState()=>NotificationBarState();
}
类NotificationBarState使用SingleTickerProviderStateMixin扩展状态{
动画控制器;
动画偏移;
@凌驾
void initState(){
super.initState();
controller=AnimationController(vsync:this,duration:duration(毫秒:200));
//偏移=Tween(开始:offset.zero,结束:offset(1.0,0.0))。动画(控制器);从右侧开始
偏移=Tween(开始:偏移.0,结束:偏移(0.0,-1.0))。设置动画(控制器);
controller.forward();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:堆栈(
),
);
}
}
我的同学们已经厌倦了实现它,但这是错误的

class NotificationBarController  extends ChangeNotifier {
  NotificationBarController({@required TickerProvider vsync}): _animationController = AnimationController(vsync: vsync);

  Animation<double> get animation => _animationController?.view ?? kAlwaysCompleteAnimation;

  Animation<double> get state => _animationController?.view ?? kAlwaysCompleteAnimation;

}
类NotificationBarController扩展ChangeNotifier{
NotificationBarController({@required TickerProvider vsync}):\u animationController=animationController(vsync:vsync);
动画获取动画=>\u animationController?.view??Kalways完成动画;
动画获取状态=>\u animationController?.view??Kalways完成动画;
}

您可以使用GlobalKey。 首先,您需要像这样实例化和存储它
final key=GlobalKey()。然后,您可以通过调用
key.currentState.someMethod()
来访问状态及其成员


然而,对我来说,整个想法看起来并不是那么简单。我建议订阅NotificationBarState和fire动画中的一些stream或changeNotifier,作为对新事件或通知的反应

我需要实现代码才能知道如何进行检查谢谢,我想这不是我想要的。请将此库视为单独课堂上的动画控制器。这与原始问题相差甚远。对此错误,我深表歉意
class NotificationBarController  extends ChangeNotifier {
  NotificationBarController({@required TickerProvider vsync}): _animationController = AnimationController(vsync: vsync);

  Animation<double> get animation => _animationController?.view ?? kAlwaysCompleteAnimation;

  Animation<double> get state => _animationController?.view ?? kAlwaysCompleteAnimation;

}