我正在尝试使用flutter 1.0,dart 2.1和Android Studio 3.2.1向远程服务器发送POST请求,但是由于某种原因,远程服务器没有收到任何请求。我尝试在自己的服务器上使用,也尝试使用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