Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Created December 5, 2022 03:46
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 jtmuller5/d810a3dc1856c6cec65501155f21b026 to your computer and use it in GitHub Desktop.
Save jtmuller5/d810a3dc1856c6cec65501155f21b026 to your computer and use it in GitHub Desktop.
silent-marsh-8079
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Stack(
children: [
SpinningGradient(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 36.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
TextSpan(
children: [
TextSpan(
text: 'The clock is ',
style: TextStyle(fontSize: 60, fontWeight: FontWeight.bold),
),
TextSpan(
text: 'ticking',
style: TextStyle(fontSize: 60, color: Colors.white, fontWeight: FontWeight.bold),
),
TextSpan(
text: '.',
style: TextStyle(fontSize: 60, fontWeight: FontWeight.bold),
),
],
),
),
],
),
),
],
),
),
);
}
}
class SpinningGradient extends StatefulWidget {
@override
_SpinningGradientState createState() => _SpinningGradientState();
}
class _SpinningGradientState extends State<SpinningGradient> with SingleTickerProviderStateMixin {
late AnimationController _animationController;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 5),
);
_animationController.repeat();
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _animationController,
builder: (context, child) {
return Transform.rotate(
angle: -_animationController.value * 2.0 * 3.14,
child: Transform.scale(
scale: 3,
child: ClipPath(
clipper: CircleClipper(),
child: Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
gradient: SweepGradient(
center: Alignment.center,
colors: [
Colors.white,
Colors.pink,
],
stops: [
0.5,
1.0,
],
tileMode: TileMode.mirror,
),
),
clipBehavior: Clip.none,
),
),
));
},
);
}
}
class CircleClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
var path = Path();
path.addOval(
Rect.fromCircle(
center: Offset(size.width / 2, size.height / 2),
radius: min(size.width, size.height) / 2,
),
);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment