Skip to content

Instantly share code, notes, and snippets.

@peekpt
Created December 6, 2019 12:53
Show Gist options
  • Save peekpt/5be23b577e99856e2bbd223c6df69299 to your computer and use it in GitHub Desktop.
Save peekpt/5be23b577e99856e2bbd223c6df69299 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: TriangleError(),
),
),
);
}
}
class TriangleError extends StatefulWidget {
const TriangleError({Key key}) : super(key: key);
@override
_TriangleErrorState createState() => _TriangleErrorState();
}
class _TriangleErrorState extends State<TriangleError>
with TickerProviderStateMixin {
AnimationController rotationController;
@override
void initState() {
rotationController = AnimationController(
duration: const Duration(milliseconds: 2000),
vsync: this,
)..repeat();
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(10),
child: Center(
child: AspectRatio(
aspectRatio: 1,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: RotationTransition(
turns:
Tween(begin: 0.0, end: 1.0).animate(rotationController),
child: ClipPath(
clipper: TrianglePath(),
child: LayoutBuilder(
builder: (context, constrains) {
return Container(
// uncomment and reload view
// color: Colors.red,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).primaryColorLight,
Theme.of(context)
.primaryColorLight
.withAlpha(10)
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
margin: EdgeInsets.all(constrains.maxHeight / 8),
);
},
),
),
),
),
],
),
),
),
);
}
}
class TrianglePath extends CustomClipper<Path> {
var radius = 10.0;
@override
Path getClip(Size size) {
Path path = Path();
path.lineTo(size.width / 4, 0);
path.lineTo(size.width / 2, size.height / 2);
path.lineTo(size.width - size.width / 4, 0);
path.lineTo(0, 0);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
@peekpt
Copy link
Author

peekpt commented Dec 6, 2019

load animation then uncomment and reload view

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