Advertisement
ZawXtut

flutter_SanDev_customPainter

Nov 30th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.74 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatelessWidget {
  6.   @override
  7.   Widget build(BuildContext context) {
  8.     // return Center(
  9.     //   child: CustomPaint(),
  10.     // );
  11.     return MaterialApp(
  12.       title: 'Material App',
  13.       home: Scaffold(
  14.         appBar: AppBar(
  15.           title: Text('Material App Bar'),
  16.         ),
  17.         body: Column(
  18.           children: [
  19.             // Container(child: RaisedButton()),
  20.             Container(
  21.               child: Stack(
  22.                 children: [
  23.                   Container(
  24.                     color: Colors.red,
  25.                     child: CustomPaint(
  26.                       painter: MyPainter3(),
  27.                     ),
  28.                   ),
  29.                   Container(
  30.                     color: Colors.red,
  31.                     child: CustomPaint(
  32.                       painter: MyPainter2(),
  33.                     ),
  34.                   ),
  35.                   Container(
  36.                     color: Colors.yellow,
  37.                     child: CustomPaint(
  38.                       painter: MyPainter(),
  39.                     ),
  40.                   ),
  41.                   // Container(
  42.                   //   margin: EdgeInsets.only(top: 200),
  43.                   //   height: 300,
  44.                   //   color: Colors.green.withOpacity(0.4),
  45.                   //   child: CustomPaint(
  46.                   //     painter: MyStar(),
  47.                   //   ),
  48.                   // )
  49.                 ],
  50.               ),
  51.             ),
  52.             // Container(child: RaisedButton())
  53.           ],
  54.         ),
  55.       ),
  56.     );
  57.   }
  58. }
  59.  
  60. class MyStar extends CustomPainter {
  61.   @override
  62.   void paint(Canvas canvas, Size size) {
  63.     // final left = 50.0;
  64.     // final top = 100.0;
  65.     // final right = 250.0;
  66.     // final bottom = 200.0;
  67.     // final rect = Rect.fromLTRB(left, top, right, bottom);
  68.     var paint = Paint();
  69.     //   ..color = Colors.black
  70.     //   ..style = PaintingStyle.stroke
  71.     //   ..strokeWidth = 4;
  72.     // canvas.drawRect(rect, paint);
  73.   }
  74.  
  75.   @override
  76.   bool shouldRepaint(covariant CustomPainter oldDelegate) {
  77.     // TODO: implement shouldRepaint
  78.     return false;
  79.   }
  80. }
  81.  
  82. class MyPainter3 extends CustomPainter {
  83.   @override
  84.   void paint(Canvas canvas, Size size) {
  85.     var paint = Paint();
  86.     paint.color = Colors.red;
  87.  
  88.     paint.style = PaintingStyle.fill;
  89.     var path = Path();
  90.     path.moveTo(0, size.height * 0.8);
  91.     path.quadraticBezierTo(10, 400, 550, 0);
  92.     //path.quadraticBezierTo(0, 500, 300, 0);
  93.  
  94.     canvas.drawPath(path, paint);
  95.   }
  96.  
  97.   @override
  98.   bool shouldRepaint(covariant CustomPainter oldDelegate) {
  99.     return false;
  100.   }
  101. }
  102.  
  103. class MyPainter2 extends CustomPainter {
  104.   @override
  105.   void paint(Canvas canvas, Size size) {
  106.     var paint = Paint();
  107.     paint.color = Colors.yellow;
  108.  
  109.     paint.style = PaintingStyle.fill;
  110.     var path = Path();
  111.     path.moveTo(0, size.height * 0.8);
  112.     path.quadraticBezierTo(10, 360, 510, 0);
  113.     //path.quadraticBezierTo(0, 500, 300, 0);
  114.  
  115.     canvas.drawPath(path, paint);
  116.   }
  117.  
  118.   @override
  119.   bool shouldRepaint(covariant CustomPainter oldDelegate) {
  120.     // TODO: implement shouldRepaint
  121.     return false;
  122.   }
  123. }
  124.  
  125. class MyPainter extends CustomPainter {
  126.   @override
  127.   void paint(Canvas canvas, Size size) {
  128.     var paint = Paint();
  129.     paint.color = Colors.blue;
  130.  
  131.     paint.style = PaintingStyle.fill;
  132.     var path = Path();
  133.     path.moveTo(0, size.height * 0.8);
  134.     path.quadraticBezierTo(0, 300, 500, 0);
  135.     //path.quadraticBezierTo(0, 500, 300, 0);
  136.  
  137.     canvas.drawPath(path, paint);
  138.   }
  139.  
  140.   @override
  141.   bool shouldRepaint(covariant CustomPainter oldDelegate) {
  142.     //throw UnimplementedError();
  143.     return false;
  144.   }
  145. }
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement