English | 简体中文
A Flutter library that models spring dynamics and adds real world physics to your app. inspired by Facebook Rebound
To use this plugin, add flutter_rebound as a dependency in your pubspec.yaml file.
// Import packageimport'package:flutter_rebound/flutter_rebound.dart';
import'package:flutter/material.dart';
classMyHomePageextendsStatefulWidget {
MyHomePage({Key key, this.title}) :super(key: key);
finalString title;
@override_MyHomePageStatecreateState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> withTickerProviderStateMixin {
SpringSystem system;
Spring spring;
double _scale =1;
@overridevoidinitState() {
super.initState();
system =SpringSystem(vsync:this);
spring = system.createSpring(40, 3);
spring.addUpdateListener((spring) {
double value = spring.currentValue;
_scale =1- value *0.5;
setState(() {});
});
spring.endValue =1;
}
@overridevoiddispose() {
system.dispose();
super.dispose();
}
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
title:Text(widget.title),
),
body:Center(
child:Transform.scale(
scale: _scale,
child:Container(
width:200,
height:200,
color:Colors.red,
),
),
),
);
}
}