Flutter tween 基本动画在内部不起作用FutureBuilder
我已经使用 gridview.builder 创建了一个图片库页面,但是由于futurebuilder
某种原因动画在里面不起作用。我直接在身体容器内的静态图像上尝试了相同的动画,它工作得非常好。需要一些方法来为futurebuilder中的网络图像设置动画。
class _GalleryGridState extends State<GalleryGrid>
with TickerProviderStateMixin {
AnimationController _controller;
Animation _squeezeOutAnimation, transformationAnim;
List<GalleryModel> lists = List();
Future<List<GalleryModel>> fetchPost() async {
final response =
await http.get("https://jsonplaceholder.typicode.com/photos");
if (response.statusCode == 200) {
var datas = json.decode(response.body);
lists = (datas as List)
.map((data) => new GalleryModel.fromJson(data))
.toList();
return lists;
} else {
throw Exception("Failed to load photos");
}
}
@override
void initState() {
super.initState();
_controller =
AnimationController(duration: Duration(seconds: 3), vsync: this);
transformationAnim = BorderRadiusTween(
begin: BorderRadius.circular(150.0),
end: BorderRadius.circular(0.0))
.animate(CurvedAnimation(parent: _controller, curve: Curves.ease));
_squeezeOutAnimation = Tween<double>(begin: 150.0, end: 1000.0)
.animate(CurvedAnimation(parent: _controller, curve: Curves.ease));
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: fetchPost(),
builder: (context, data) {
switch (data.connectionState) {
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
default:
return GridView.builder(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
itemCount: lists.length,
itemBuilder: (BuildContext context, int index) {
return Stack(
children: <Widget>[
Container(
child: Card(
shape: BeveledRectangleBorder(
borderRadius: transformationAnim.value),
elevation: 10.0,
child: GestureDetector(
onTap: () {
_controller.forward();
},
child: Container(
width: _squeezeOutAnimation.value,
height: _squeezeOutAnimation.value,
child: Image.network(
lists[index].thumbnailUrl,
fit: BoxFit.fill,
width: _squeezeOutAnimation.value,
),
),
),
),
),
])