'flutter multiple postwith php api problem

I am sending multiple user_id with form data in a flutter to PHP page but my PHP API did not see array or obj. I used this code for other projects it could work with javascript but I could no work with flutter. my flutter code=

    Future<FormData> grupDuzenleData() async {
  var token = await dbcon.tumKullanicilar();
if (grupPhoto != null) {
    var fileName = path.basename(grupPhoto.path);
    return FormData.fromMap(
      {
        'token': token.single['token'],
        'group_description': grupHakkindaController.text ?? '',
        'music_type': _currentType ?? '',
        'city': _currentCity ?? '',
        'group_name': grupAdiController.text ?? '',
        'group_id': widget.BandID ?? '',
        'id': uyeler,
        'image':
            await MultipartFile.fromFile(grupPhoto.path, filename: fileName)
      },
    );
  } else {
    return FormData.fromMap(
      {
        'token': token.single['token'],
        'group_description': grupHakkindaController.text ?? '',
        'music_type': _currentType ?? '',
        'city': _currentCity ?? '',
        'id': uyeler,
        'group_id': widget.BandID ?? '',
        'group_name': grupAdiController.text ?? '',
      },
    );
  }
}
````````````````````````
**my other flutter functions**
````````````````````````
void grupDuzenleKaydet() async {
    var dio = Dio();
    Response response;
    var formData = await grupDuzenleData();

    response = await dio.post(
      //"/upload",
      ApiURL().URL('groupEdit'),
      data: formData,

      onSendProgress: (received, total) {
        if (total != -1) {
          print((received / total * 100).toStringAsFixed(0) + '%');
        }
      },
    );
    if (response.statusCode == 200) {
      Map<String, dynamic> _responseMap = json.decode(response.data);
      await showDialog(
          context: context,
          builder: (BuildContext context) {
            return PlatformDuyarliAlertDialog(
                baslik: '${_responseMap['sonuc']}',
                icerik: '',
                anaButonYazisi: '');
          });
    } else {
      Map<String, dynamic> _responseMap = json.decode(response.data);
      await showDialog(
        context: context,
        builder: (BuildContext context) {
          return PlatformDuyarliAlertDialog(
              baslik: '${_responseMap['sonuc']}',
              icerik: '',
              anaButonYazisi: '');
        },
      );
    }
  }
````````````````````````
My php code =
I get post from flutter.
````````````````````````
$token= @strip_tags($_POST["token"]);
$group_id= @strip_tags($_POST["group_id"]);
$user_id = @strip_tags($_POST["id"]);
$group_name = @strip_tags($_POST["group_name"]);
$image = @$_FILES["image"];
$description = strip_tags($_POST["group_description"]);
$music_type = strip_tags($_POST["music_type"]);
$city = strip_tags($_POST["city"]);
$user = new user();
$token_bak = @$user->userTokenCheck($token);
if($token=="" or !$token or $token_bak<=0){
  $sonuc = "Lütfen Üye Girişi Yapın.";
  $sonuclar = array("kod"=>"1","sonuc"=>$sonuc);
  echo json_encode_tr($sonuclar);
} elseif ($group_name=="" or !$group_name) {
  $sonuc = "Lütfen Grup Adını Girin.";
  $sonuclar = array("kod"=>"1","sonuc"=>$sonuc);
  echo json_encode_tr($sonuclar);
} elseif ($description=="" or !$description) {
  $sonuc = "Lütfen Grup Açıklamasını Girin.";
  $sonuclar = array("kod"=>"1","sonuc"=>$sonuc);
  echo json_encode_tr($sonuclar);
} elseif ($music_type=="" or !$music_type or $music_type=="0") {
  $sonuc = "Lütfen Grubun Genelde Çaldığı Müzik Türünü Seçin.";
  $sonuclar = array("kod"=>"1","sonuc"=>$sonuc);
  echo json_encode_tr($sonuclar);
} elseif ($city=="" or !$city) {
  $sonuc = "Lütfen Grubun Genelde Sahne Aldığı Şehiri Seçin.";
  $sonuclar = array("kod"=>"1","sonuc"=>$sonuc);
  echo json_encode_tr($sonuclar);
} else {
  if($image!=""){
    if(isset($_FILES['image'])){
      $hata = $_FILES['image']['error'];
      if($hata != 0) {
        echo 'Yüklenirken bir hata gerçekleşmiş.';
      } else {
          $tip = $_FILES['image']['type'];
          $isim = $_FILES['image']['name'];
          $uzanti = explode('.', $isim);
          $uzanti = $uzanti[count($uzanti)-1];
          $uzanti_bak=fileTypeControl($uzanti);
          $tip_bak=fileTypeControl2($tip);
          if($uzanti_bak==1) {
            $sonuc="Yalnızca Fotoğraf Yükleyebilirsiniz (jpg,jpeg,png).";
            $sonuclar= array("kod"=>"1","sonuc"=>$sonuc);
            echo json_encode_tr($sonuclar);
          } elseif ($tip_bak==1) {
            $sonuc="Yalnızca  Türünde Fotoğraf Yükleyebilirsiniz (jpg,jpeg,png).";
            $sonuclar= array("kod"=>"1","sonuc"=>$sonuc);
            echo json_encode_tr($sonuclar);
          } else {
            $dosya = $_FILES['image']['tmp_name'];
            copy($dosya, '../uploads/group_images/' . $_FILES['image']['name']);
            $avatar2='uploads/group_images/'.$_FILES['image']['name'].'';
          }
        }
      }
  } else {
    $avatar2="";
  }
  if(isset($user_id) AND count($user_id)>0){
    for ($i=0; $i <= count($user_id); $i++){
      $user_id_ekle = $user_id[$i];
      $ekle = new GroupMemberAdd($user_id_ekle, $group_id);
    }
  }
  $sonuc = "$user_id[0] ve $user_id[1]";
  $sonuclar = array("kod"=>"1","sonuc"=>$sonuc);
  echo json_encode_tr($sonuclar);
  new GroupEdit($group_id, $token, $group_name, $description, $avatar2, $music_type, $city);
}

Very interesting my user_id is not come to be array or object my english is very bad i am sory



Solution 1:[1]

SOLVED ? used explode function after i did foreach. it solves. Thank you all.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arkin