Untitled
unknown
plain_text
2 years ago
4.0 kB
8
Indexable
class ImageCropScreen extends StatefulWidget {
String image;
double aspectRatio;
ImageCropScreen({Key? key, required this.image, required this.aspectRatio})
: super(key: key);
@override
State<ImageCropScreen> createState() => _ImageCropScreenState();
}
class _ImageCropScreenState extends State<ImageCropScreen> {
// Uint8List? _imageDataList;
// ValueNotifier<bool> isDisplayPhoto = ValueNotifier(true);
final GlobalKey _cropperKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: ColorConst.blackColor,
body: Column(
children: [
Expanded(
child: Cropper(
cropperKey: _cropperKey,
overlayColor: ColorConst.blackColor.withOpacity(0.6),
backgroundColor: ColorConst.blackColor,
overlayType: OverlayType.rectangle,
aspectRatio: widget.aspectRatio,
image: Image.file(
File(widget.image),
fit: BoxFit.fill,
))),
SafeArea(
child: Container(
padding: EdgeInsets.only(
bottom: Dimensions.h25,
top: Dimensions.h12,
left: Dimensions.commonPaddingForScreen,
right: Dimensions.commonPaddingForScreen),
decoration: BoxDecoration(
color: const Color(0xf0161616).withOpacity(0.9985939860343933),
boxShadow: const [
BoxShadow(
color: Color(0x29ffffff),
offset: Offset(0, -0.5),
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Cancel
InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: CustomTextWidget.regularSFProText(
text: AppString.cancel,
fontSize: Dimensions.sp17,
fontWeight: FontWeight.normal,
color: ColorConst.cupertinoBlue,
),
),
// Upload New
InkWell(
onTap: () {
setState(() {
selectImageFromSystem();
});
},
child: CustomTextWidget.regularSFProText(
text: AppString.uploadNew,
fontSize: Dimensions.sp17,
fontWeight: FontWeight.normal,
color: ColorConst.cupertinoBlue,
),
),
// Done
InkWell(
onTap: () {
changeToDisplayImage();
},
child: CustomTextWidget.regularSFProText(
text: AppString.done,
fontSize: Dimensions.sp17,
fontWeight: FontWeight.normal,
color: ColorConst.cupertinoBlue,
),
),
],
),
),
)
],
),
);
}
// void changeToEditImage() {
// isDisplayPhoto.value = false;
// }
void changeToDisplayImage() async {
final imageBytes = await Cropper.crop(
cropperKey: _cropperKey,
);
Navigator.pop(context, imageBytes);
}
// Image Picker
Future<void> selectImageFromSystem() async {
final pickedImage = await ImagePicker().pickImage(
source: ImageSource.gallery,
maxHeight: 1800,
maxWidth: 1800,
);
if (pickedImage != null) {
widget.image = '';
widget.image = (pickedImage.path.toString());
setState(() {});
}
}
}
Editor is loading...
Leave a Comment