2017-07-26 9 views
1

私はアニメーションが終了した後でアクションを実行しようとしています。私はstatusListenerを追加しようとしましたが、それは私のために働いていません。完了するアニメーションを聞きます

@override 
    void initState() { 
    super.initState(); 
    _controller = new AnimationController(
     duration: new Duration(milliseconds: 500), 
     vsync: this, 
    )..addStatusListener((AnimationStatus status) { 
     print("Going"); 
     if (status.index == 3 && spins > 0) { // AnimationStatus index 3 == completed animation 
     _controller.duration = new Duration(milliseconds: speed - 50); 
     _controller.forward(from: _controller.value == null ? 0.0 : 1 - _controller.value); 
     spins--; 
     print(speed); 
     } 
    }); 
    } 

print(Going);が実行されることは決してありませんが、私のアニメーションが終了処理を行います。私のコードは次のようになります。何がうまくいかないのですか?

/// ---編集--- ///私はAnimatedBuilder使用してい

は、コードの一部は、次のようになります。

child: new AnimatedBuilder(
    animation: _controller, 
    child: new Image.network(widget.url), 
    builder: (BuildContext context, Widget child) { 
    return new Transform.rotate(
     angle: _controller.value * 2.0 * math.PI, 
     child: child, 
    ); 
    }, 
), 

答えて

1

あなたのコメントへの反応と編集私はAnimationBuilderを調べました。私はこのワーキング解決策を考え出したdocsに例を適応:あなたが見ることができるように

class Spinner extends StatefulWidget { 
    @override 
    _SpinnerState createState() => new _SpinnerState(); 
} 

class _SpinnerState extends State<Spinner> with SingleTickerProviderStateMixin { 
    AnimationController _controller; 
    CurvedAnimation _animation; 

    @override 
    void initState() { 
    super.initState(); 
    _controller = new AnimationController(
     duration: const Duration(seconds: 5), 
     vsync: this, 
    )..forward(); 

    _animation = new CurvedAnimation(
     parent: _controller, 
     curve: Curves.linear, 
    )..addStatusListener((AnimationStatus status) { 
     if (status == AnimationStatus.completed) 
     print('completed'); 
    }); 
    } 

    @override 
    void dispose() { 
    _controller.dispose(); 
    super.dispose(); 
    } 

    @override 
    Widget build(BuildContext context) { 
    return new AnimatedBuilder(
     animation: _animation, 
     child: new Container(width: 200.0, height: 200.0, color: Colors.green), 
     builder: (BuildContext context, Widget child) { 
     return new Transform.rotate(
      angle: _controller.value * 2.0 * 3.1415, 
      child: child, 
     ); 
     }, 
    ); 
    } 
} 

、私はAnimationBuilder用アニメーションとして使用されたよりも、アニメーション、親としてのコントローラを使用していました。それが役に立てば幸い。

1

は例のに続いて私はこれのwiをテストしていない

_controller = new AnimationController(
    duration: const Duration(milliseconds: 1500), 
    vsync: this, 
)..forward(); 

_animation = new CurvedAnimation(
    parent: _controller, 
    curve: const Interval(0.0, 0.9, curve: Curves.fastOutSlowIn), 
    reverseCurve: Curves.fastOutSlowIn 
)..addStatusListener((AnimationStatus status) { 
    if (status == AnimationStatus.dismissed) 
    _controller.forward(); 
    else if (status == AnimationStatus.completed) 
    _controller.reverse(); 
}); 

フラッターギャラリーのprogress indicatorsアニメーションにStatusListenerを添付しなければならない、ではないコントローラあなたのコード。

+0

私は 'AnimatedBuilder'を使っていることを忘れていました(投稿を編集してコードを追加しました)。私が書いたもの、他のアイデアにあなたの方法を適用できるとは思いませんか? –

関連する問題