Projeto enviando com API. Foi um pouco confuso mas consegui.
import 'dart:convert';
import 'package:http/http.dart';
Future<void> sendProduct(Map<String, dynamic> product) async {
String url = 'https://api.github.com/gists/33b84374a96cadc4e3aee103458e32fd';
String chave = 'minha.chave.gist';
Response response = await post(
Uri.parse(url),
headers: {
'Authorization': 'Bearer $chave',
'Content-Type': 'application/json'
},
body: json.encode({
'description': 'descricao do gist',
'public': true,
'files': {
'products.json': {
'content': json.encode(product),
}
}
}),
);
if (response.statusCode == 200) {
print('produto enviado');
} else {
print('erro ao enviar produto ${response.statusCode}');
}
}
void main() {
var newProduct = {
"id": 4,
"name": "Monitor",
"price": 800.00
};
sendProduct(newProduct);
}
// curl -L \
// -X PATCH \
// -H "Accept: application/vnd.github+json" \
// -H "Authorization: Bearer <YOUR-TOKEN>" \
// -H "X-GitHub-Api-Version: 2022-11-28" \
// https://api.github.com/gists/GIST_ID \
// -d '{"description":"An updated gist description","files":{"README.md":{"content":"Hello World from GitHub"}}}'