Я пытаюсь отправить POST-запрос на удаленный сервер, используя flutter 1.0, dart 2.1 и Android Studio 3.2.1, но по какой-то причине удаленный сервер не получает ничего. Я пытался использовать на своем собственном сервере, и я пытался использовать Firebase, но безуспешно. Может ли кто-нибудь помочь мне исправить мою ошибку? Вот мой код:
void addProduct(String title, String description, double price,
String image) {
final Map<String, dynamic> productData = {
'title': title,
'description': description,
'image': 'url',
'price': price
};
http.post('https://fir-numbers.firebaseio.com/products.json', body: json.encode(productData));
final Product newProduct = Product(
title: title,
description: description,
price: price,
image: image,
userEmail: _authenticatedUser.email,
userId: _authenticatedUser.id);
_products.add(newProduct);
notifyListeners();
}
Также наверху у меня есть
import 'dart:convert';
import 'package:scoped_model/scoped_model.dart';
import 'package:http/http.dart' as http;
и в моем pubspec.yaml у меня есть
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
scoped_model: ^0.3.0
http: ^0.12.0