import 'dart:convert'; import 'package:flutter/services.dart'; import 'package:http/http.dart' as http; import 'package:http_parser/http_parser.dart'; class HttpUtils { var client = http.Client(); Future performHttpRequest( Uint8List imageBytes, String imageName) async { var postUri = Uri.parse("http://130.61.88.150/upload"); http.MultipartRequest request = http.MultipartRequest("POST", postUri); http.MultipartFile multipartFile = http.MultipartFile.fromBytes( 'file', imageBytes, filename: 'lorem.png', contentType: MediaType('image', 'png'), ); request.files.add(multipartFile); http.StreamedResponse response = await client.send(request); http.Response finalResponse = await http.Response.fromStream(response); var lang = ""; if (finalResponse.statusCode == 200) { Map jsonData = jsonDecode(finalResponse.body); lang = jsonData['language']; } else { throw ('Error: ${finalResponse.statusCode}'); } return lang; } }