Home > Blockchain >  The argument type can't be assigned to the parameter type 'List<int>'
The argument type can't be assigned to the parameter type 'List<int>'

Time:02-17

I have a Flask python backend that returns an image in form of a list, I'd like to get this image data to my Flutter app and then convert it to a file, but I get this error

The argument type 'Response' can't be assigned to the parameter type 'List'

Return image is in this format

[67, 53, 81], [69, 55, 83], [72, 59, 85], [68, 55, 79], [62, 50, 72], [52, 39, 61], [44, 32, 52], [44, 30, 48], [47, 34, 50], [41, 24, 38], [47, 30, 43], [46, 29, 40], [32, 13, 22], [42, 23, 32], [59, 38, 47], [52, 31, 40], [54, 30, 40], [57, 33, 43], [74, 50, 60], [76, 53, 61], [66, 46, 51], [68, 47, 50], [72, 51, 54], [57, 36, 38], [57, 37, 36], [61, 41, 40], [62, 43, 40], [71, 52, 49], [77, 58, 55], [81, 62, 59], [78, 59, 56],.....

Flutter code:

Future pix(String BackgroundImagePath, String originalImagePath) async {
  final uri = Uri.parse('http://127.0.0.1:5000').replace( queryParameters : {
  'original': originalImagePath,
  'background': BackgroundImagePath,
  });

  final response = await http.get(uri);

  final tempDir = await getTemporaryDirectory();
  File file = await File('${tempDir.path}/image.png').create();
  file.writeAsBytesSync(response); //error here
  return file;
}

CodePudding user response:

Actually the variable response is an object of Response class from http package. So if your response body is List<int> then you will have to pass response.body. And if it is String, you will have to convert it to Unit8List.

  • Related