Created with <3 with dartpad.dev.
Created
November 8, 2023 02:42
-
-
Save hongsw/324b75a3d6db5e2ddf722c24701685bc to your computer and use it in GitHub Desktop.
flying-flora-4095
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main.dart | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
// Remove the debug banner | |
debugShowCheckedModeBanner: false, | |
home: HomePage(color: Colors.blue), | |
); | |
} | |
} | |
class HomePage extends StatefulWidget { | |
final Color color; | |
const HomePage({Key? key, this.color= Colors.grey}) : super(key: key); | |
@override | |
State<HomePage> createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> with TickerProviderStateMixin { | |
// animation controller | |
late AnimationController _controller; | |
// animation color | |
late Animation<Color?> _color; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = AnimationController( | |
duration: const Duration(seconds: 5), | |
vsync: this, | |
)..repeat(reverse: true); | |
// color tween | |
_color = | |
ColorTween(begin: Colors.red, end: widget.color).animate(_controller); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
alignment: Alignment.center, | |
color: Colors.black87, | |
child: AnimatedBuilder( | |
animation: _color, | |
builder: (BuildContext _, Widget? __) { | |
return Container( | |
width: 300, | |
height: 300, | |
decoration: | |
BoxDecoration(color: _color.value, shape: BoxShape.circle), | |
); | |
}, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment