Skip to content

Commit a041608

Browse files
Merge branch 'icapps:main' into main
2 parents 9860513 + ff8efd4 commit a041608

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,6 @@ build/
7474
!**/ios/**/default.perspectivev3
7575

7676
test/coverage_helper_test.dart
77-
coverage/**
77+
coverage/**
78+
.fvm/
79+
.vscode/settings.json

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.0.7] - 2023-08-09
2+
3+
* Added Ratio as new shape and arguments
4+
15
## [0.0.6]
26

37
* Added new param to CustomImageCrop for new image fit types

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ An Image cropper that is customizable
1111

1212
# CustomImageCrop
1313

14-
```
14+
```dart
1515
CustomImageCrop(
1616
cropController: controller,
1717
image: const AssetImage('assets/test.png'),
@@ -23,35 +23,51 @@ You can provide the image using any Imageprovider.
2323
## Parameters
2424

2525
### required image
26+
2627
The image that needs to be cropped
2728

2829
### cropController
30+
2931
The controller used to adjust the image and crop it.
3032

3133
### overlayColor
34+
3235
The color above the image that will be cropped
3336

3437
### backgroundColor
38+
3539
The color behind the image. This color will also be used when there are gaps/empty space after the cropping
3640

3741
### shape
42+
3843
The shape of the cropping path.
3944

4045
### cropPercentage
46+
4147
How big the crop should be in regards to the width and height available to the cropping widget.
4248

4349
### drawPath
50+
4451
How the border of the crop should be painted. default DottedCropPathPainter.drawPath and SolidCropPathPainter.drawPath are provided, but you can create/provide any CustomPaint.
4552

4653
### pathPaint
4754
Custom painting for the crop area border style.
4855

4956
### canRotate
57+
5058
Whether to allow the image to be rotated.
5159

5260
### customProgressIndicator
61+
5362
Custom widget for progress indicator.
5463

64+
### ratio
65+
66+
Ratio of the cropping area.
67+
If ` shape`` is set to `CustomCropShape.Ratio`, this property is required.
68+
For example, to create a square crop area, use `[`Ratio(width: 1, height: 1)`.
69+
To create a rectangular crop area with a 16:9 aspect ratio, use `[`Ratio(width: 16, height: 9)`.
70+
5571
# Controller Methods
5672

5773
## addTransition
@@ -67,11 +83,13 @@ Add the position, angle and scale to the current state. This can be used to adju
6783
Set the position, angle and scale to the specified values. This can be used to center the image by pressing a button for example.
6884

6985
## reset
86+
7087
`void reset()`
7188

7289
Reset the image to its default state
7390

7491
## onCropImage
92+
7593
`Future<MemoryImage> onCropImage()`
7694

7795
Crops the image in its current state, this will return a MemoryImage that contains the cropped image
@@ -80,7 +98,7 @@ Crops the image in its current state, this will return a MemoryImage that contai
8098

8199
See example/lib
82100

83-
```
101+
```dart
84102
class MyHomePage extends StatefulWidget {
85103
final String title;
86104
@@ -148,4 +166,3 @@ class _MyHomePageState extends State<MyHomePage> {
148166
}
149167
}
150168
```
151-

example/lib/main.dart

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,9 @@ class _MyHomePageState extends State<MyHomePage> {
9090
child: CustomImageCrop(
9191
cropController: controller,
9292
// image: const AssetImage('assets/test.png'), // Any Imageprovider will work, try with a NetworkImage for example...
93-
image: const NetworkImage(
94-
'https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png'),
93+
image: const NetworkImage('https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png'),
9594
shape: _currentShape,
96-
ratio: _currentShape == CustomCropShape.Ratio
97-
? Ratio(width: _width, height: _height)
98-
: null,
95+
ratio: _currentShape == CustomCropShape.Ratio ? Ratio(width: _width, height: _height) : null,
9996
canRotate: true,
10097
canMove: false,
10198
canScale: false,
@@ -111,47 +108,34 @@ class _MyHomePageState extends State<MyHomePage> {
111108
Row(
112109
mainAxisAlignment: MainAxisAlignment.spaceAround,
113110
children: [
114-
IconButton(
115-
icon: const Icon(Icons.refresh), onPressed: controller.reset),
116-
IconButton(
117-
icon: const Icon(Icons.zoom_in),
118-
onPressed: () =>
119-
controller.addTransition(CropImageData(scale: 1.33))),
120-
IconButton(
121-
icon: const Icon(Icons.zoom_out),
122-
onPressed: () =>
123-
controller.addTransition(CropImageData(scale: 0.75))),
124-
IconButton(
125-
icon: const Icon(Icons.rotate_left),
126-
onPressed: () =>
127-
controller.addTransition(CropImageData(angle: -pi / 4))),
128-
IconButton(
129-
icon: const Icon(Icons.rotate_right),
130-
onPressed: () =>
131-
controller.addTransition(CropImageData(angle: pi / 4))),
111+
IconButton(icon: const Icon(Icons.refresh), onPressed: controller.reset),
112+
IconButton(icon: const Icon(Icons.zoom_in), onPressed: () => controller.addTransition(CropImageData(scale: 1.33))),
113+
IconButton(icon: const Icon(Icons.zoom_out), onPressed: () => controller.addTransition(CropImageData(scale: 0.75))),
114+
IconButton(icon: const Icon(Icons.rotate_left), onPressed: () => controller.addTransition(CropImageData(angle: -pi / 4))),
115+
IconButton(icon: const Icon(Icons.rotate_right), onPressed: () => controller.addTransition(CropImageData(angle: pi / 4))),
132116
IconButton(
133117
icon: const Icon(Icons.crop),
134118
onPressed: () async {
135119
final image = await controller.onCropImage();
136120
if (image != null) {
137-
Navigator.of(context).push(MaterialPageRoute(
138-
builder: (BuildContext context) =>
139-
ResultScreen(image: image)));
121+
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => ResultScreen(image: image)));
140122
}
141123
},
142124
),
143125
PopupMenuButton<CustomCropShape>(
144126
icon: const Icon(Icons.crop_original),
145127
onSelected: _changeCropShape,
146128
itemBuilder: (BuildContext context) {
147-
return CustomCropShape.values.map((shape) {
148-
return PopupMenuItem<CustomCropShape>(
149-
value: shape,
150-
child: getShapeIcon(shape),
151-
);
152-
}).toList();
129+
return CustomCropShape.values.map(
130+
(shape) {
131+
return PopupMenuItem<CustomCropShape>(
132+
value: shape,
133+
child: getShapeIcon(shape),
134+
);
135+
},
136+
).toList();
153137
},
154-
)
138+
),
155139
],
156140
),
157141
if (_currentShape == CustomCropShape.Ratio)

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: custom_image_crop
22
description: An image cropper that is customizable. You can rotate, scale and translate either through gestures or a controller
3-
version: 0.0.6
3+
version: 0.0.7
44
homepage: https://github.com/icapps/flutter-custom-image-crop
55

66
environment:

0 commit comments

Comments
 (0)