Change Image in Flutter

Picking up image is one of the important thing in any application. User want to select various image, upload it and various other reasons. Making a functionality for picking image is one of the crucial part of mobile development and also for other platforms. Writing code the from the scratch can be hard therefore various developers across the globe developed various packages to make others developers easy to write a code. Image picker is one of the common package used to pick a image from gallery or camera.

var profileImgPath=''.obs;

changeImage(context) async{
try{
final img= await ImagePicker().pickImage(
source:ImageSource.gallery,
    imageQuality:70);
if(img=null)return;
profileImgPath.value=img.path;
}
 on PlatformException catch(e){
VxToast.show(context,msg:e.toString());
}
}

I make a function changeImage(context) which use ImagePicker package to pick a image from gallery. Here profileImgPath is used to store the value of path. I am using Getx as state management therefore I use obs. We can use this fuction as below.

ElevatedButton(
onPressed:(){
changeImage(context);
}
),