Created
July 31, 2023 08:58
-
-
Save givip/d3d9bdc8fac9eaa91f37e4ec4bca40dd to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const Scaffold( | |
body: Center( | |
child: SpaceshipBeaming(), | |
), | |
), | |
); | |
} | |
} | |
class SpaceshipBeaming extends StatefulWidget { | |
const SpaceshipBeaming({super.key}); | |
@override | |
SpaceshipBeamingState createState() => SpaceshipBeamingState(); | |
} | |
class SpaceshipBeamingState extends State<SpaceshipBeaming> | |
with SingleTickerProviderStateMixin { | |
late AnimationController _animation; | |
@override | |
void initState() { | |
super.initState(); | |
_animation = AnimationController( | |
duration: const Duration(seconds: 5), | |
vsync: this, | |
)..repeat(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Stack( | |
alignment: AlignmentDirectional.center, | |
children: <Widget>[ | |
const Positioned( | |
child: ColoredBox( | |
color: Colors.black, | |
), | |
), | |
AnimatedBuilder( | |
animation: _animation, | |
builder: (_, __) { | |
return ClipPath( | |
clipper: const BeamClipper(), | |
child: Container( | |
height: 1000, | |
decoration: BoxDecoration( | |
gradient: RadialGradient( | |
radius: 1.5, | |
colors: const [ | |
Colors.yellow, | |
Colors.transparent, | |
], | |
stops: [0, _animation.value], | |
), | |
), | |
), | |
); | |
}, | |
), | |
const FlutterLogo(size: 50), | |
], | |
); | |
} | |
@override | |
void dispose() { | |
_animation.dispose(); | |
super.dispose(); | |
} | |
} | |
class BeamClipper extends CustomClipper<Path> { | |
const BeamClipper(); | |
@override | |
getClip(Size size) { | |
return Path() | |
..lineTo(size.width / 2, size.height / 2) | |
..lineTo(size.width, size.height) | |
..lineTo(0, size.height) | |
..lineTo(size.width / 2, size.height / 2) | |
..close(); | |
} | |
/// Return false always because we always clip the same area. | |
@override | |
bool shouldReclip(CustomClipper oldClipper) => false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment