Я - новая пчела во флаттере. Я получаю изображения из методов getimagecamera () и getimagegallery (), и я устанавливаю изображения в текст на основе изображений, полученных этими методами. Теперь мне нужно добавить эти изображения в список. У меня есть 3 кнопки в пользовательском интерфейсе, для которых мне нужно взять 3 изображения, чтобы добавить его в список. Теперь, когда я получаю 6 изображений, мне нужно поставить условие на основе того, откуда я получаю изображение (из галереи / камеры) , мне нужна помощь, чтобы реализовать logi c .pls help
Future getImageFromCamera(String button) async {
print("Picker is called");
var image = await ImagePicker.pickImage(source: ImageSource.camera,imageQuality: 85);
setState(() {
File _image_camera = image;
String imagepath_camera =_image_camera.path.toString();
print('Select image path' +imagepath_camera);
imageName_camera = _image_camera.path.split("/").last;
if (button == "PhotoOne") {
image1_camera = imageName_camera;
image1 = null;
print("camera img from Btn1 = $image1_camera");
setState(() {
if(image1!=null){
buildingImages.insert(0, imagepath_camera);
//buildingImages[0]=imageName_camera;
}
else{
buildingImages.insert(0,imagepath_camera);
}
});
}
if (button == "PhotoTwo") {
image2_camera = imageName_camera;
image2 = null;
print("camera img from Btn2 = $image2_camera");
if(image2!=null){
buildingImages[1]=imageName_camera;
}
else{
buildingImages.add(imageName_camera);
}
}
if (button == "PhotoThree") {
image3_camera = imageName_camera;
image3 = null;
print("camera img from Btn3 = $image3_camera");
if(image3!=null){
buildingImages[2]=imageName_camera;
}
else{
buildingImages.add(imageName_camera);
}
}
print(imageName_camera);
});
}
Future getImageFromGallery(String button) async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery,imageQuality: 85);
setState(() {
File _image_gallery = image;
String imagePathGallery= _image_gallery.path.toString();
print('Select image path' + imagePathGallery);
imageName_gallery = _image_gallery.path.split("/").last;
if (button == "PhotoOne") {
image1_camera = null;
image1 = imageName_gallery;
print("img from button1 in gallery $image1");
setState(() {
if(image1_camera!=null){
// buildingImages[0]=imageName_gallery;
buildingImages.insert(0,imagePathGallery);
}
else {
buildingImages.insert(0,imagePathGallery);
}
});
}
if (button == "PhotoTwo") {
image2_camera = null;
image2 = imageName_gallery;
print("img from button2 in gallery $image2");
if(image2_camera!=null){
buildingImages[1]=imageName_gallery;
}
else{
buildingImages.add(imageName_gallery);
}
}
if (button == "PhotoThree") {
image3_camera = null;
image3 = imageName_gallery;
print("img from button3 in gallery $image3");
if(image3_camera!=null){
buildingImages[2]=imageName_gallery;
}
else{
buildingImages.add(imageName_gallery);
}
}
print(imageName_gallery);
});
}
Future uploadmultipleimage(BuildContext context,List<String> buildingImages) async {
String buildingImgPath1,buildingImgPath2,BuildingImgPath3;
List<String> img=[];
img.add(
"/storage/emulated/0/Android/data/com.stark.ukbocw_cesspayment/files/Pictures/scaled_4403d401-17d5-4035-aeea-b996f8b8ae02-1006291291.jpg");
img.add(
"/storage/emulated/0/Android/data/com.stark.ukbocw_cesspayment/files/Pictures/scaled_4403d401-17d5-4035-aeea-b996f8b8ae02-1006291291.jpg");
img.add(
"/storage/emulated/0/Android/data/com.stark.ukbocw_cesspayment/files/Pictures/scaled_4403d401-17d5-4035-aeea-b996f8b8ae02-1006291291.jpg");
print(" list size == ${buildingImages.length}");
var uri =
Uri.parse("http://bocwboarduk.in/api/PropertyDetails/PostPropDetails");
http.MultipartRequest request = new http.MultipartRequest('POST', uri);
request.fields['geo_id'] = propertyDetails.geoId.toString();
request.fields['Name'] = myControllername.text;
request.fields['Address'] =myControlleraddress.text ;
request.fields['PhoneNumber'] = myControllerPhoneNumber.text;
request.fields['email'] = myControllerEmailID.text;
request.fields['Plotarea'] = myControllerPlotArea.text;
request.fields['nooffloors'] = myControllerNumberOfFloors.text;
request.fields['typeofbuilding'] = myControllerTypeOfBuilding.text;
request.fields['constructioncost'] = myControllerConstructionCost.text;
//request.fields['estimatedcost']=propertyDetails.estimatedCess.toString();
List<MultipartFile> newList = new List<MultipartFile>();
for (int i = 0; i < img.length; i++) {
File imageFile = File(img[i].toString());
var stream =
new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));
var length = await imageFile.length();
if (i == 0) {
var multipartFile = new http.MultipartFile(
"buildingimage1", stream, length,
filename: basename(imageFile.path));
newList.add(multipartFile);
}
else if (i == 1) {
var multipartFile = new http.MultipartFile(
"buildingimage2", stream, length,
filename: basename(imageFile.path));
newList.add(multipartFile);
}
else if (i == 2) {
var multipartFile = new http.MultipartFile("proof", stream, length,
filename: basename(imageFile.path));
newList.add(multipartFile);
}
}
request.files.addAll(newList);
var response = await request.send();
print("@@ multi part response == $response");
print("@@ multi part status code == ${response.statusCode}");
if (response.statusCode == 200) {
print("@@ Image Uploaded ======= ");
//Navigator.pop(context);
}
else {
print("Upload Failed");
}
response.stream.transform(utf8.decoder).listen((value) {
print("@@ stream value == $value");
});
}