Skip to content

Commit

Permalink
Implement #48.
Browse files Browse the repository at this point in the history
  • Loading branch information
deakjahn committed Apr 21, 2024
1 parent 07a64ab commit 5a49de0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ CropImage(
gridCornerColor: Colors.white,
/// The size of the corner of the crop grid. Defaults to 25.
gridCornerSize: 50,
/// Whether to display the corners. Defaults to true.
showCorners: true,
/// The width of the crop grid thin lines. Defaults to 2.
gridThinWidth: 3,
/// The width of the crop grid thick lines. Defaults to 5.
Expand Down Expand Up @@ -138,4 +140,4 @@ file.writeAsBytes(bytes, flush);

`croppedBitmap()` – and consequently, `croppedImage()` – result in an exception on Flutter Web with the HTML web renderer.
The culprit is `Picture.toImage()` that doesn't work with it (see https://github.com/flutter/engine/pull/20750).
Consider using CanvasKit for the web renderer (which is much better than HTML, anyway).
Consider using CanvasKit for the web renderer (which is much better than HTML, anyway).
44 changes: 22 additions & 22 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,26 @@ class _MyHomePageState extends State<MyHomePage> {

Future<void> _finished() async {
final image = await controller.croppedImage();
// ignore: use_build_context_synchronously
await showDialog<bool>(
context: context,
builder: (context) {
return SimpleDialog(
contentPadding: const EdgeInsets.all(6.0),
titlePadding: const EdgeInsets.all(8.0),
title: const Text('Cropped image'),
children: [
Text('relative: ${controller.crop}'),
Text('pixels: ${controller.cropSize}'),
const SizedBox(height: 5),
image,
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('OK'),
),
],
);
},
);
if (mounted)
await showDialog<bool>(
context: context,
builder: (context) {
return SimpleDialog(
contentPadding: const EdgeInsets.all(6.0),
titlePadding: const EdgeInsets.all(8.0),
title: const Text('Cropped image'),
children: [
Text('relative: ${controller.crop}'),
Text('pixels: ${controller.cropSize}'),
const SizedBox(height: 5),
image,
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('OK'),
),
],
);
},
);
}
}
}
2 changes: 1 addition & 1 deletion lib/src/crop_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class CropGrid extends StatelessWidget {
final Color gridCornerColor;
final double paddingSize;
final double cornerSize;
final bool showCorners;
final double thinWidth;
final double thickWidth;
final Color scrimColor;
final bool showCorners;
final bool alwaysShowThirdLines;
final bool isMoving;
final ValueChanged<Size> onSize;
Expand Down
9 changes: 8 additions & 1 deletion lib/src/crop_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class CropImage extends StatefulWidget {
/// Defaults to 25.
final double gridCornerSize;

/// Whether to display the corners.
///
/// Defaults to true.
final bool showCorners;

/// The width of the crop grid thin lines.
///
/// Defaults to 2.
Expand Down Expand Up @@ -112,6 +117,7 @@ class CropImage extends StatefulWidget {
this.paddingSize = 0,
this.touchSize = 50,
this.gridCornerSize = 25,
this.showCorners = true,
this.gridThinWidth = 2,
this.gridThickWidth = 5,
this.scrimColor = Colors.black54,
Expand Down Expand Up @@ -150,6 +156,7 @@ class CropImage extends StatefulWidget {
properties.add(DiagnosticsProperty<double>('touchSize', touchSize));
properties
.add(DiagnosticsProperty<double>('gridCornerSize', gridCornerSize));
properties.add(DiagnosticsProperty<bool>('showCorners', showCorners));
properties.add(DiagnosticsProperty<double>('gridThinWidth', gridThinWidth));
properties
.add(DiagnosticsProperty<double>('gridThickWidth', gridThickWidth));
Expand Down Expand Up @@ -271,7 +278,7 @@ class _CropImageState extends State<CropImage> {
final double width = _getWidth(maxWidth, maxHeight);
final double height = _getHeight(maxWidth, maxHeight);
size = Size(width, height);
final bool showCorners =
final bool showCorners = widget.showCorners &&
widget.minimumImageSize != widget.maximumImageSize;
return Stack(
alignment: Alignment.center,
Expand Down

0 comments on commit 5a49de0

Please sign in to comment.