preface
I believe many friends have this need when making flutter, so I will go directly on it. First, take a look at the pictures
Talk about the components that are used
# local imageImage_picker: ^ 0.6.0 + 4# Cut the pictureImage_cropper: ^ 1.0.2Copy the code
Then I do Android, I need to find the file gradle.properties in Android and add these two lines
On IOS, the first component just adds a key and it becomes naturally supported
android.enableJetifier=true
android.useAndroidX=true
Copy the code
My demo code is directly posted here
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:image_cropper/image_cropper.dart'; Class ModifyAvator extends StatefulWidget {final String URL; final String id; ModifyAvator(this.url, this.id); @override _ModifyAvatorState createState() => _ModifyAvatorState(); } class _ModifyAvatorState extends State<ModifyAvator> { File _image; // Future getImage() async {print('click me \n'); // Imagesource.gallery // imagesource.camera // imagesource.gallery // imagesource.camera/imagesource.gallery // imagesource.camerasource: ImageSource.gallery); // Call the second clipping component File croppedFile = await imagecropper.cropImage (sourcePath: image.path,
ratioX: 1.0,
ratioY: 1.0,
maxWidth: 512,
maxHeight: 512,
);
setState(() {
print('>>>>>>>>>>\n $croppedFile');
_image = croppedFile;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image Picker Example'), ), body: Container( width: ScreenUtil().setWidth(750), // height: ScreenUtil().setHeight(300), color: Colors. Black, child: Center(// add child: _image == null? Image.network( Uri.decodeComponent(widget.url.replaceAll("_"."%"), fit: boxFit.contain,) : image.file (_image),),), // add floatingActionButton: floatingActionButton (onPressed: getImage, tooltip:'Pick Image', child: Icon(Icons.add_a_photo), ), ); }}Copy the code
conclusion
Sorry, no epilogue. HHHHHH….