Skip to content

Instantly share code, notes, and snippets.

@mono0926
Last active March 24, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mono0926/e47dfb6d0dbc030002658cce7c5ee2d5 to your computer and use it in GitHub Desktop.
Save mono0926/e47dfb6d0dbc030002658cce7c5ee2d5 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primarySwatch: Colors.red),
title: 'Flutter Demo',
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
AnimationController _animation;
Animation<double> _radiusAnimation;
@override
void initState() {
super.initState();
_animation = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1000),
);
_radiusAnimation = _animation.drive(Tween<double>(
begin: 0.2,
end: 0.5,
));
_animation.repeat(reverse: true);
}
@override
void dispose() {
_animation.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: AnimatedBuilder(
animation: _radiusAnimation,
builder: (context, child) => CustomPaint(
painter: Sky(radius: _radiusAnimation.value),
child: child,
),
child: SizedBox.expand(),
),
);
}
}
class Sky extends CustomPainter {
const Sky({
@required this.radius,
}) : super();
final double radius;
@override
void paint(Canvas canvas, Size size) {
var rect = Offset.zero & size;
var gradient = RadialGradient(
center: Alignment.center,
radius: radius,
colors: const [Color(0xFFFF0000), Color(0xFFFFCCFF)],
stops: [0.2, 1.0],
);
canvas.drawRect(
rect,
Paint()..shader = gradient.createShader(rect),
);
}
@override
bool shouldRepaint(Sky oldDelegate) => oldDelegate.radius != radius;
}
@mono0926
Copy link
Author

2019-03-24_22-21-42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment