How to slow down a fling animation in Flutter? -


i playing fling animation based on grid demo in flutter gallery. made example below work, animation plays fast. barely see unless slow down using timedilation. changing value of velocity doesn't seem have effect. should @ else? thanks!

import 'package:flutter/animation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart' show timedilation;  const klogourl =     "https://raw.githubusercontent.com/dart-lang/logos/master/logos_and_wordmarks/dart-logo.png";  class logowidget extends statelesswidget {   // leave out height , width fills animating parent   build(buildcontext context) {     return new container(         margin: new edgeinsets.symmetric(vertical: 10.0),         child: new image.network(klogourl));   } }  class translatetransition extends statelesswidget {   translatetransition({this.child, this.animation});    widget child;   animation<offset> animation;    widget build(buildcontext context) {     return new animatedbuilder(         animation: animation,         builder: (buildcontext context, widget child) {           return new center(             child: new transform(               transform: new matrix4.identity()                 ..translate(animation.value.dx, animation.value.dy),               child: new container(                 height: 100.0,                 width: 100.0,                 child: child,               ),             ),           );         },         child: child);   } }  class logoapp extends statefulwidget {   logoappstate createstate() => new logoappstate(); }  class logoappstate extends state<logoapp> tickerproviderstatemixin {   animation<offset> _flinganimation;   animationcontroller _controller;    initstate() {     super.initstate();     timedilation = 5.0;      _controller = new animationcontroller(       vsync: this,     );      _flinganimation = new tween<offset>(       begin: new offset(-150.0, -150.0),       end: new offset(150.0, 150.0),     )         .animate(_controller);      _controller       ..value = 0.0       ..fling(velocity: 0.1)       ..addlistener(() { //        print(_flinganimation.value);       });   }    widget build(buildcontext context) {     return new translatetransition(         child: new logowidget(), animation: _flinganimation);   }    @override   dispose() {     _controller.dispose();   } }  void main() {   runapp(new logoapp()); } 

fling uses springsimulation default parameters, 1 of spring constant. if start velocity zero, spring spring @ speed determined spring constant. what's happening you're going 0.0 1.0 pretty tight critically-damped string.

also, because you're using networkimage, don't see because image takes longer load animation takes run.

if replace logowidget flutterlogo, you'll see what's happening better.

if want go slower, can use animatewith instead of fling pass specific springsimulation own custom parameters.

the existence of fling bit of historical accident. it's designed used animationcontrollers lowerbound , upperbound given in pixels, rather on 0.0...1.0 default range.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -