upload image flutter code example

Example 1: flutter image load

Image.asset(name) is essentially Image(image: AssetImage(name)),
Image.file(path) is essentially Image(image: FileImage(File(path))),
Image.network(url) is essentially Image(image: NetworkImage(url)),
Image.memory(list) is essentially Image(image: MemoryImage(list))

Example 2: uploading image flutter

var d = "$tmpFile";
      var dd = d.split("'");
      var filename = dd[1].split('/').last;
      FormData formData = new FormData.fromMap({
        "user_id": "3225",
        "image": await MultipartFile.fromFile(dd[1], filename: "$filename"),
      });
      var response = await dio.post(
        'http://10.0.2.2/test/upload.php',
        data: formData,
        onSendProgress: (received, total) {
          if (total != -1) {
            print((received / total * 100).toStringAsFixed(0) + "%");
          }
        },
      );
      print(response);