Skip to content

Commit 506b40c

Browse files
committed
Create BaseShape.
1 parent 709f588 commit 506b40c

File tree

7 files changed

+48
-38
lines changed

7 files changed

+48
-38
lines changed
Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
import 'dart:ui';
22

33
abstract class Shape {
4-
double get x => _x;
4+
double get x;
55

6-
double get y => _y;
7-
8-
final Color color;
9-
10-
Shape({
11-
required double x,
12-
required double y,
13-
required this.color,
14-
}) : _x = x,
15-
_y = y;
16-
17-
void paint(Canvas can);
6+
double get y;
187

198
double get width;
209

2110
double get height;
2211

23-
void centerToFit() {
24-
_x -= width / 2;
25-
_y -= height / 2;
26-
}
12+
Color get color;
2713

28-
void translate(double x, double y) {
29-
_x += x;
30-
_y += y;
31-
}
14+
void paint(Canvas can);
3215

33-
double _x;
34-
double _y;
16+
void centerToFit();
3517
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:flutter/material.dart';
2+
3+
import '../pattern/shape.dart';
4+
5+
abstract class BaseShape implements Shape {
6+
@override
7+
double get x => _x;
8+
9+
@override
10+
double get y => _y;
11+
12+
@override
13+
final Color color;
14+
15+
BaseShape({
16+
required double x,
17+
required double y,
18+
required this.color,
19+
}) : _x = x,
20+
_y = y;
21+
22+
@override
23+
void centerToFit() {
24+
_x -= width / 2;
25+
_y -= height / 2;
26+
}
27+
28+
double _x;
29+
double _y;
30+
}

patterns/abstract_factory/tool_panel_factory/shapes/circle_shape.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import 'dart:ui';
1+
import 'package:flutter/material.dart';
22

3-
import 'package:flutter/cupertino.dart';
3+
import 'base_shape.dart';
44

5-
import '../pattern/shape.dart';
6-
7-
class CircleShape extends Shape {
5+
class CircleShape extends BaseShape {
86
final double radius;
97
final bool isFilled;
108

patterns/abstract_factory/tool_panel_factory/shapes/line_shape.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'dart:ui';
22

3-
import 'package:flutter/cupertino.dart';
3+
import 'package:flutter/material.dart';
44

5-
import '../pattern/shape.dart';
5+
import 'base_shape.dart';
66

7-
class LineShape extends Shape {
7+
class LineShape extends BaseShape {
88
final double length;
99

1010
LineShape({

patterns/abstract_factory/tool_panel_factory/shapes/star_shape.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import 'dart:ui';
33

44
import 'package:flutter/material.dart';
55

6-
import '../pattern/shape.dart';
6+
import 'base_shape.dart';
77

8-
class StarShape extends Shape {
8+
class StarShape extends BaseShape {
99
final double radius;
1010
final bool isFilled;
1111

patterns/abstract_factory/tool_panel_factory/shapes/text_shape.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'dart:ui';
22

3-
import '../pattern/shape.dart';
3+
import 'base_shape.dart';
44

5-
class TextShape extends Shape {
5+
class TextShape extends BaseShape {
66
final String text;
77
final double fontSize;
88

patterns/abstract_factory/tool_panel_factory/shapes/triangle_shape.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'dart:math';
22
import 'dart:ui';
33

4-
import 'package:flutter/cupertino.dart';
4+
import 'package:flutter/material.dart';
55

6-
import '../pattern/shape.dart';
6+
import 'base_shape.dart';
77

8-
class TriangleShape extends Shape {
8+
class TriangleShape extends BaseShape {
99
final double sideLength;
1010
final bool isFilled;
1111

0 commit comments

Comments
 (0)