Created
August 15, 2019 16:11
-
-
Save shivampandey0/b2834146809d0795a8f1c3887e97ec2d to your computer and use it in GitHub Desktop.
Simple code snippet for Indian Flag (Add ashok_chakra.png in assets)
This file contains 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(MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: HomeScreen(), | |
)); | |
class HomeScreen extends StatefulWidget { | |
@override | |
_HomeScreenState createState() => _HomeScreenState(); | |
} | |
class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin { | |
AnimationController _controller; | |
@override | |
void initState() { | |
_controller = | |
AnimationController(duration: const Duration(minutes: 5), vsync: this); | |
super.initState(); | |
_controller.repeat(); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Column( | |
children: <Widget>[ | |
ClipPath( | |
clipper: CustomShapeClipper(), | |
child: Container( | |
height: MediaQuery.of(context).size.height * .5, | |
color: Color.fromRGBO(255, 153, 51, 1), | |
), | |
), | |
AnimatedBuilder( | |
animation: _controller, | |
child: Image.asset( | |
'assets/images/ashok_chakra.png', | |
height: 100.0, | |
width: 100.0, | |
), | |
builder: (BuildContext context, Widget _widget) { | |
return Transform.rotate( | |
angle: _controller.value * 300, | |
child: _widget, | |
); | |
}, | |
), | |
RotatedBox( | |
quarterTurns: 2, | |
child: ClipPath( | |
clipper: CustomShapeClipper(), | |
child: Container( | |
height: MediaQuery.of(context).size.height * 0.5 - 100, | |
color: Color.fromRGBO(19, 136, 8, 1), | |
), | |
), | |
), | |
], | |
), | |
); | |
} | |
} | |
class CustomShapeClipper extends CustomClipper<Path> { | |
@override | |
getClip(Size size) { | |
final Path path = Path(); | |
path.lineTo(0.0, size.height); | |
var firstEndPoint = Offset(size.width * 0.5, size.height - 30.0); | |
var firstControlPoint = Offset(size.width * 0.25, size.height - 50); | |
path.quadraticBezierTo(firstControlPoint.dx, firstControlPoint.dy, | |
firstEndPoint.dx, firstEndPoint.dy); | |
var secondEndPoint = Offset(size.width, size.height - 80.0); | |
var secondControlPoint = Offset(size.width * .75, size.height - 10); | |
path.quadraticBezierTo(secondControlPoint.dx, secondControlPoint.dy, | |
secondEndPoint.dx, secondEndPoint.dy); | |
path.lineTo(size.width, 0.0); | |
path.close(); | |
return path; | |
} | |
@override | |
bool shouldReclip(CustomClipper oldClipper) => true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment