1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin //TickerProviderStateMixin
double value=0; var clampSimulation=ClampingScrollSimulation(position: 200, velocity: 1); Ticker tic;
@override void initState() { super.initState(); tic=createTicker((elapsed) { if (!clampSimulation.isDone(elapsed.inMicroseconds/1000)) { setState(() { value=clampSimulation.x(elapsed.inMicroseconds/1000); }); } }); } //动画设置 Center( child: GestureDetector( onTap: () {if (!tic.isActive) {tic.start();}}, child: Container( height: 100, width: 100, color: Colors.red, margin: EdgeInsets.only(left: value), alignment: Alignment.center, child: Text('点我开始动画',), ), ), )
|