Issue
When I choose image from gallery or take photo from camera, what should've been done is cropping the image first before saving the image to the profile picture. But when I select the image from gallery, it instantly closed the app (lost connection to device).
Here is my code:
class ProfilePage extends StatefulWidget {
const ProfilePage({Key? key}) : super(key: key);
}
enum AppState {
cropped,
}
class _ProfilePageState extends State<ProfilePage> {
@override
File? image;
Future getImage() async {
final ImagePicker _picker = ImagePicker();
final XFile? imagePicked = await _picker.pickImage(source: ImageSource.gallery);
cropImage(imagePicked!.path);
}
Future getCamera() async {
final ImagePicker _picker = ImagePicker();
final XFile? imageCamera = await _picker.pickImage(source: ImageSource.camera);
cropImage(imageCamera!.path);
}
Future cropImage(filePath) async {
File? croppedImage = await ImageCropper.cropImage(
sourcePath: filePath,
aspectRatioPresets: [
CropAspectRatioPreset.square,
],
androidUiSettings: AndroidUiSettings(
toolbarTitle: 'Crop image',
toolbarColor: Color(0xFF2481CF),
toolbarWidgetColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false),
iosUiSettings: IOSUiSettings(
minimumAspectRatio: 1.0,
)
);
if (croppedImage != null) {
setState(() {
image = croppedImage;
});
}
}
Here is the error log:
How to solve this?
Solution
try adding this code:
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
to your android/app/src/main/AndroidManifest.xml
Answered By - Tarish
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.