Created with <3 with dartpad.dev.
Last active
February 6, 2023 15:40
-
-
Save gausoft/8fa53956a940db8a8c0ac2330333ef4f to your computer and use it in GitHub Desktop.
Dart Customer marker drown with custom painter
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(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MarkerWidget(), | |
); | |
} | |
} | |
class MarkerWidget extends StatefulWidget { | |
@override | |
_MarkerWidgetState createState() => _MarkerWidgetState(); | |
} | |
class _MarkerWidgetState extends State<MarkerWidget> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Testing'), | |
), | |
body: Center( | |
child: Stack(alignment: Alignment.center, children: [ | |
CustomPaint( | |
size: const Size(70, 80), | |
painter: MarkerPainter(), | |
), | |
const Icon(Icons.add, color: Colors.white) | |
]), | |
), | |
); | |
} | |
} | |
class MarkerPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
Paint paint1 = Paint(); | |
paint1 | |
..color = Colors.brown | |
..style = PaintingStyle.fill | |
..strokeWidth = 0; | |
double width = size.width; | |
double height = size.height; | |
Path path = Path(); | |
path.moveTo(0.5 * width, height * 0.1); | |
path.cubicTo(0.09 * width, height * 0.1, -0.25 * width, height * 0.6, | |
0.5 * width, height); | |
path.moveTo(0.5 * width, height * 0.1); | |
path.cubicTo(0.9 * width, height * 0.1, 1.25 * width, height * 0.6, | |
0.5 * width, height); | |
canvas.drawPath(path, paint1); | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) => false; | |
} |
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(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MarkerWidget(), | |
); | |
} | |
} | |
class MarkerWidget extends StatefulWidget { | |
@override | |
_MarkerWidgetState createState() => _MarkerWidgetState(); | |
} | |
class _MarkerWidgetState extends State<MarkerWidget> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Testing'), | |
), | |
body: Center( | |
child: Stack( | |
children: [ | |
CustomPaint( | |
size: const Size(80, 80), | |
// painter: MarkerPainter(), | |
painter: RPSCustomPainter(), | |
), | |
// const Positioned( | |
// top: 2, | |
// left: 0, | |
// right: 0, | |
// child: Icon(Icons.add_circle_outline, color: Colors.white), | |
// ), | |
], | |
), | |
), | |
); | |
} | |
} | |
class MarkerPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
Paint paint1 = Paint(); | |
paint1 | |
..color = Colors.brown | |
..style = PaintingStyle.fill | |
..strokeWidth = 0; | |
double width = size.width; | |
double height = size.height; | |
Path path = Path(); | |
path.moveTo(0.5 * width, height * 0.1); | |
path.cubicTo(0.09 * width, height * 0.1, -0.25 * width, height * 0.6, | |
0.5 * width, height); | |
path.moveTo(0.5 * width, height * 0.1); | |
path.cubicTo(0.9 * width, height * 0.1, 1.25 * width, height * 0.6, | |
0.5 * width, height); | |
canvas.drawPath(path, paint1); | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) => false; | |
} | |
//Copy this CustomPainter code to the Bottom of the File | |
class RPSCustomPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
Path path_0 = Path(); | |
path_0.moveTo(size.width * 0.3364609, size.height * 0.9798242); | |
path_0.cubicTo( | |
size.width * 0.05267578, | |
size.height * 0.5684199, | |
0, | |
size.height * 0.5261973, | |
0, | |
size.height * 0.3750000, | |
); | |
path_0.cubicTo( | |
0, | |
size.height * 0.1678926, | |
size.width * 0.1678926, | |
0, | |
size.width * 0.3750000, | |
0, | |
); | |
path_0.cubicTo( | |
size.width * 0.5821074, | |
0, | |
size.width * 0.7500000, | |
size.height * 0.1678926, | |
size.width * 0.7500000, | |
size.height * 0.3750000, | |
); | |
path_0.cubicTo( | |
size.width * 0.7500000, | |
size.height * 0.5261973, | |
size.width * 0.6973242, | |
size.height * 0.5684199, | |
size.width * 0.4135391, | |
size.height * 0.9798242, | |
); | |
path_0.cubicTo( | |
size.width * 0.3949160, | |
size.height * 1.006727, | |
size.width * 0.3550820, | |
size.height * 1.006725, | |
size.width * 0.3364609, | |
size.height * 0.9798242, | |
); | |
path_0.close(); | |
Paint paint_0_fill = Paint()..style = PaintingStyle.fill; | |
paint_0_fill.color = Color(0xff000000).withOpacity(1.0); | |
canvas.drawPath(path_0, paint_0_fill); | |
} | |
@override | |
bool shouldRepaint(covariant CustomPainter oldDelegate) { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment