After 2 days, I found the only API which provide 1000 free API calls each month and after that 0.01$ per request if you place their logo. It's working like a charm:
https://dashboard.photoroom.com. You have to create an account, after that you'll get the API Key. The content, header and all the details for the implementation you will find here:
https://www.notion.so/photoroom/API-Documentation-public-4eb3e45d9c814f92b6392b7fd0f1d51f.
I used this code below:
Future removeBackground(context, setState, Uint8List image) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(max: 100, msg: 'Removing background...',
backgroundColor: const Color(0xff393432),
progressValueColor: const Color(0xff393432),
progressBgColor: const Color(0xffE4BCB4),
msgColor: const Color(0xffE4BCB4),);
final appDir = await getTemporaryDirectory();
File file = File('${appDir.path}/sth.jpg');
await file.writeAsBytes(image);
var headers = {
'x-api-key': '72fe87f131787350e933dcdf80c775fdcf0ad704'
};
var request = http.MultipartRequest('POST', Uri.parse('
https://sdk.photoroom.com/v1/segment'));
request.files.add(await http.MultipartFile.fromPath('image_file', file.path));
request.headers.addAll(headers);
var response = await request.send();
if (response.statusCode == 200) {
final List _bytes = [];
response.stream.listen((value) {
_bytes.addAll(value);
}).onDone(() async {
await file.writeAsBytes(_bytes);
pd.close();
setState(() {
var a = CleverCloset.base64String(file.readAsBytesSync());
stackChildren.add(MoveableStackItem(CleverCloset.imageFromBase64String(a).image));
});
});
}
else {
setState(() {
var base64String = CleverCloset.base64String(image);
stackChildren.add(MoveableStackItem(CleverCloset.imageFromBase64String(base64String).image));
});
}
}