Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added borderColor #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class _CropSampleState extends State<CropSample> {
}

var _isSumbnail = false;
var _useBorders = false;
var _isCropping = false;
var _isCircleUi = false;
Uint8List? _croppedData;
Expand Down Expand Up @@ -117,6 +118,7 @@ class _CropSampleState extends State<CropSample> {
children: [
if (_imageDataList.isNotEmpty)
Crop(
borderColor: _useBorders ? Colors.black : null,
controller: _cropController,
image: _imageDataList[_currentImage],
onCropped: (croppedData) {
Expand All @@ -143,6 +145,20 @@ class _CropSampleState extends State<CropSample> {
? const SizedBox.shrink()
: const DotControl(),
),
Positioned(
right: 16,
bottom: 60,
child: GestureDetector(
onTap: () => setState(() => _useBorders = !_useBorders),
child: CircleAvatar(
backgroundColor:
_useBorders ? Colors.blue.shade50 : Colors.blue,
child: Center(
child: Icon(Icons.border_outer_rounded),
),
),
),
),
Positioned(
right: 16,
bottom: 16,
Expand Down
30 changes: 27 additions & 3 deletions lib/src/crop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class Crop extends StatelessWidget {
/// If default dot Widget with different color is needed, [DotControl] is available.
final CornerDotBuilder? cornerDotBuilder;

/// [Color] of the image border
/// When [borderColor] is set, a border with the given color is added to the
/// image exterior, making it better to see the image ending when
/// the [baseColor] and the image background are similar
final Color? borderColor;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we accept Border, not only Color?
It enables users to decide other configurations, such as width.


const Crop({
Key? key,
required this.image,
Expand All @@ -80,6 +86,7 @@ class Crop extends StatelessWidget {
this.maskColor,
this.baseColor = Colors.white,
this.cornerDotBuilder,
this.borderColor,
}) : assert((initialSize ?? 1.0) <= 1.0,
'initialSize must be less than 1.0, or null meaning not specified.'),
super(key: key);
Expand All @@ -106,6 +113,7 @@ class Crop extends StatelessWidget {
maskColor: maskColor,
baseColor: baseColor,
cornerDotBuilder: cornerDotBuilder,
borderColor: borderColor,
),
);
},
Expand All @@ -126,6 +134,7 @@ class _CropEditor extends StatefulWidget {
final Color? maskColor;
final Color baseColor;
final CornerDotBuilder? cornerDotBuilder;
final Color? borderColor;

const _CropEditor({
Key? key,
Expand All @@ -141,6 +150,7 @@ class _CropEditor extends StatefulWidget {
this.maskColor,
required this.baseColor,
this.cornerDotBuilder,
this.borderColor,
}) : super(key: key);

@override
Expand Down Expand Up @@ -306,9 +316,23 @@ class _CropEditorState extends State<_CropEditor> {
color: widget.baseColor,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Image.memory(
widget.image,
fit: _isFitVertically ? BoxFit.fitHeight : BoxFit.fitWidth,
child: Flex(
direction: _isFitVertically ? Axis.vertical : Axis.horizontal,
children: [
Expanded(
child: Container(
foregroundDecoration: (widget.borderColor != null && widget.maskColor == null)
? BoxDecoration(
border: Border.all(color: widget.borderColor!, width: 2),
)
: null,
child: Image.memory(
widget.image,
fit: _isFitVertically ? BoxFit.fitHeight : BoxFit.fitWidth,
),
),
),
],
),
),
IgnorePointer(
Expand Down