Created
November 24, 2020 09:37
-
-
Save frozencity/204c9a5e90f2f9bb1ac344d9bd77b05f to your computer and use it in GitHub Desktop.
This is a Drawing of Myanmar Flag written in Dart.
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
// Copyright (c) 2020, Thiha Aye Kyaw. | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.deepOrange, | |
), | |
home: MyHomePage(title: 'Myanmar Flag in Dart'), | |
); | |
} | |
} | |
class _StarClipper extends CustomClipper<Path> { | |
@override | |
Path getClip(Size size) { | |
final path = Path(); | |
path.lineTo(size.width * 0.5, size.height * 0.175); | |
path.lineTo(size.width * 0.45, size.height * 0.4); | |
path.lineTo(size.width * 0.30, size.height * 0.4); | |
path.lineTo(size.width * 0.425, size.height * 0.55); | |
path.lineTo(size.width * 0.375, size.height * 0.8); | |
path.lineTo(size.width * 0.5, size.height * 0.65); | |
path.lineTo(size.width * 0.625, size.height * 0.8); | |
path.lineTo(size.width * 0.575, size.height * 0.55); | |
path.lineTo(size.width * 0.70, size.height * 0.4); | |
path.lineTo(size.width * 0.55, size.height * 0.4); | |
path.lineTo(size.width * 0.5, size.height * 0.175); | |
path.close(); | |
return path; | |
} | |
@override | |
bool shouldReclip(CustomClipper<Path> oldClipper) => false; | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Container( | |
width: 350, | |
height: 200, | |
margin: EdgeInsets.all(16.0), | |
child: Stack( | |
children: [ | |
Positioned.fill( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Container( | |
color: MMFlagColors().mmYellow, | |
height: 50, | |
width: 250, | |
), | |
Container( | |
color: MMFlagColors().mmGreen, | |
height: 50, | |
width: 250, | |
), | |
Container( | |
color: MMFlagColors().mmRed, | |
height: 50, | |
width: 250, | |
), | |
], | |
), | |
), | |
Positioned.fill( | |
child: ClipPath( | |
child: Container( | |
color: Colors.white, | |
), | |
clipper: _StarClipper(), | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} | |
class MMFlagColors { | |
// According to Wikipedia, Myanmar Flag's colors are as follows. | |
Color mmYellow = Color(0xffFECB00); | |
Color mmGreen = Color(0xff34B233); | |
Color mmRed = Color(0xffEA2839); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment