Skip to content

Commit 948b14f

Browse files
Formatting
1 parent 58cb1c7 commit 948b14f

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-19
lines changed

example/lib/main.dart

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@ class _MyHomePageState extends State<MyHomePage> {
102102
child: CustomImageCrop(
103103
cropController: controller,
104104
// image: const AssetImage('assets/test.png'), // Any Imageprovider will work, try with a NetworkImage for example...
105-
image: const NetworkImage('https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png'),
105+
image: const NetworkImage(
106+
'https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png'),
106107
shape: _currentShape,
107-
ratio: _currentShape == CustomCropShape.Ratio ? Ratio(width: _width, height: _height) : null,
108+
ratio: _currentShape == CustomCropShape.Ratio
109+
? Ratio(width: _width, height: _height)
110+
: null,
108111
canRotate: true,
109112
canMove: true,
110113
canScale: true,
111-
borderRadius: _currentShape == CustomCropShape.Ratio ? _radius : 0,
114+
borderRadius:
115+
_currentShape == CustomCropShape.Ratio ? _radius : 0,
112116
customProgressIndicator: const CupertinoActivityIndicator(),
113117
imageFit: _imageFit,
114118
pathPaint: Paint()
@@ -121,11 +125,24 @@ class _MyHomePageState extends State<MyHomePage> {
121125
Row(
122126
mainAxisAlignment: MainAxisAlignment.spaceAround,
123127
children: [
124-
IconButton(icon: const Icon(Icons.refresh), onPressed: controller.reset),
125-
IconButton(icon: const Icon(Icons.zoom_in), onPressed: () => controller.addTransition(CropImageData(scale: 1.33))),
126-
IconButton(icon: const Icon(Icons.zoom_out), onPressed: () => controller.addTransition(CropImageData(scale: 0.75))),
127-
IconButton(icon: const Icon(Icons.rotate_left), onPressed: () => controller.addTransition(CropImageData(angle: -pi / 4))),
128-
IconButton(icon: const Icon(Icons.rotate_right), onPressed: () => controller.addTransition(CropImageData(angle: pi / 4))),
128+
IconButton(
129+
icon: const Icon(Icons.refresh), onPressed: controller.reset),
130+
IconButton(
131+
icon: const Icon(Icons.zoom_in),
132+
onPressed: () =>
133+
controller.addTransition(CropImageData(scale: 1.33))),
134+
IconButton(
135+
icon: const Icon(Icons.zoom_out),
136+
onPressed: () =>
137+
controller.addTransition(CropImageData(scale: 0.75))),
138+
IconButton(
139+
icon: const Icon(Icons.rotate_left),
140+
onPressed: () =>
141+
controller.addTransition(CropImageData(angle: -pi / 4))),
142+
IconButton(
143+
icon: const Icon(Icons.rotate_right),
144+
onPressed: () =>
145+
controller.addTransition(CropImageData(angle: pi / 4))),
129146
PopupMenuButton(
130147
icon: const Icon(Icons.crop_original),
131148
onSelected: _changeCropShape,
@@ -162,7 +179,9 @@ class _MyHomePageState extends State<MyHomePage> {
162179
onPressed: () async {
163180
final image = await controller.onCropImage();
164181
if (image != null) {
165-
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => ResultScreen(image: image)));
182+
Navigator.of(context).push(MaterialPageRoute(
183+
builder: (BuildContext context) =>
184+
ResultScreen(image: image)));
166185
}
167186
},
168187
),

lib/src/calculators/calculate_crop_fit_params.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ CropFitParams calculateCropFitParams({
3939
if (screenWidth <= screenHeight * aspectRatio) {
4040
cropSizeWidth = screenWidth * cropPercentage;
4141
cropSizeHeight = cropSizeWidth / aspectRatio;
42-
defaultScale = cropSizeWidth / max(imageWidth, imageHeight * aspectRatio);
42+
defaultScale =
43+
cropSizeWidth / max(imageWidth, imageHeight * aspectRatio);
4344
} else {
4445
cropSizeHeight = screenHeight * cropPercentage;
4546
cropSizeWidth = cropSizeHeight * aspectRatio;
46-
defaultScale = cropSizeHeight / max(imageHeight, imageWidth / aspectRatio);
47+
defaultScale =
48+
cropSizeHeight / max(imageHeight, imageWidth / aspectRatio);
4749
}
4850
break;
4951

lib/src/calculators/calculate_on_crop_params.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ OnCropParams caclulateOnCropParams({
8484
if (screenHeight * aspectRatio > screenWidth) {
8585
uiSize = screenHeight;
8686
cropSizeMax = imageHeight.toDouble();
87-
translateScale = cropSizeMax / uiSize / cropPercentage * heightToWidthRatio;
87+
translateScale =
88+
cropSizeMax / uiSize / cropPercentage * heightToWidthRatio;
8889
scale = dataScale / cropPercentage * heightToWidthRatio;
8990
} else {
9091
uiSize = screenWidth;
9192
cropSizeMax = imageWidth.toDouble();
92-
translateScale = cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
93+
translateScale =
94+
cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
9395
scale = dataScale / cropPercentage / heightToWidthRatio;
9496
}
9597
break;
@@ -102,7 +104,8 @@ OnCropParams caclulateOnCropParams({
102104
translateScale = cropSizeMax / uiSize / cropPercentage;
103105
scale = dataScale / cropPercentage;
104106
} else {
105-
translateScale = cropSizeMax / uiSize / cropPercentage * heightToWidthRatio;
107+
translateScale =
108+
cropSizeMax / uiSize / cropPercentage * heightToWidthRatio;
106109
scale = dataScale / cropPercentage * heightToWidthRatio;
107110
}
108111
break;
@@ -112,7 +115,8 @@ OnCropParams caclulateOnCropParams({
112115
uiSize = screenWidth;
113116
cropSizeMax = imageWidth.toDouble();
114117
if (screenWidth > screenHeight * aspectRatio) {
115-
translateScale = cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
118+
translateScale =
119+
cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
116120
scale = dataScale / cropPercentage / heightToWidthRatio;
117121
} else {
118122
translateScale = cropSizeMax / uiSize / cropPercentage;

lib/src/widgets/custom_image_crop_widget.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ class CustomImageCrop extends StatefulWidget {
126126
this.borderRadius = 0,
127127
Paint? imagePaintDuringCrop,
128128
Key? key,
129-
}) : this.imagePaintDuringCrop = imagePaintDuringCrop ?? (Paint()..filterQuality = FilterQuality.high),
129+
}) : this.imagePaintDuringCrop = imagePaintDuringCrop ??
130+
(Paint()..filterQuality = FilterQuality.high),
130131
assert(
131132
!(shape == CustomCropShape.Ratio && ratio == null),
132133
"If shape is set to Ratio, ratio should not be null.",
@@ -137,7 +138,8 @@ class CustomImageCrop extends StatefulWidget {
137138
_CustomImageCropState createState() => _CustomImageCropState();
138139
}
139140

140-
class _CustomImageCropState extends State<CustomImageCrop> with CustomImageCropListener {
141+
class _CustomImageCropState extends State<CustomImageCrop>
142+
with CustomImageCropListener {
141143
CropImageData? _dataTransitionStart;
142144
late Path _path;
143145
late double _width, _height;
@@ -234,7 +236,8 @@ class _CustomImageCropState extends State<CustomImageCrop> with CustomImageCropL
234236
left: data.x + _width / 2,
235237
top: data.y + _height / 2,
236238
child: Transform(
237-
transform: Matrix4.diagonal3(vector_math.Vector3(scale, scale, scale))
239+
transform: Matrix4.diagonal3(
240+
vector_math.Vector3(scale, scale, scale))
238241
..rotateZ(data.angle)
239242
..translate(-image.width / 2, -image.height / 2),
240243
child: Image(
@@ -264,7 +267,8 @@ class _CustomImageCropState extends State<CustomImageCrop> with CustomImageCropL
264267
}
265268

266269
void onScaleUpdate(ScaleEvent event) {
267-
final scale = widget.canScale ? event.scale : (_dataTransitionStart?.scale ?? 1.0);
270+
final scale =
271+
widget.canScale ? event.scale : (_dataTransitionStart?.scale ?? 1.0);
268272

269273
final angle = widget.canRotate ? event.rotationAngle : 0.0;
270274

0 commit comments

Comments
 (0)