Skip to content

Instantly share code, notes, and snippets.

@guid-empty
Last active April 8, 2021 13:55
Show Gist options
  • Save guid-empty/3d885db28ac3eb7843ef128fa0cd0223 to your computer and use it in GitHub Desktop.
Save guid-empty/3d885db28ac3eb7843ef128fa0cd0223 to your computer and use it in GitHub Desktop.
Implicit Animations - TweenAnimationBuilder
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class OtusLogo extends StatelessWidget {
final Color color;
OtusLogo({@required this.color});
@override
Widget build(BuildContext context) {
return Container(
color: color,
child: Image.network('https://github.com/flutter-cats/otus-cocktails-application/blob/master/logo-2.8602b.svg'),
width: 200.0,
height: 200.0,
);
}
}
class _MyHomePageState extends State<MyHomePage> {
static final colorTween = ColorTween(begin: Colors.red, end: Colors.green);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Implicit Animations - TweenAnimationBuilder'),
),
body: Center(
child: TweenAnimationBuilder<Color>(
tween: colorTween,
duration: Duration(seconds: 2),
builder: (_, Color colorValue, Widget child) {
return OtusLogo(color: colorValue);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment