-
Notifications
You must be signed in to change notification settings - Fork 225
/
Shapes.dart
55 lines (47 loc) · 1.38 KB
/
Shapes.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'package:flutter/material.dart';
void main() {
runApp(new RectangleClass());
}
class RectangleClass extends StatefulWidget {
@override
DrawRect createState() => new DrawRect();
}
class DrawRect extends State<RectangleClass> {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Shapes in Flutter'),
),
body: new Stack(
children: <Widget>[
new CustomPaint(
painter: new Sample(),
)
],
)),
);
}
}
class Sample extends CustomPainter {
//PaintingStyle.stroke; //This allows to shade only the borders
//strokeWidth = sets the width of rectangle
final customPaint = new Paint()
..color = new Color(0xFF0099FF)
..style = PaintingStyle.stroke
..strokeWidth = 1.5;
//Circle - dx and dy components
final offsetCircle = new Offset(200.0, 200.0);
final _drawRect = new Rect.fromLTRB(150.0, 150.0, 10.0, 400.0);
@override
void paint(Canvas canvas, Size size) {
canvas.drawRect(_drawRect, customPaint);
canvas.drawCircle(offsetCircle, 30.0, customPaint);
canvas.drawOval(_drawRect, customPaint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}