Flutter 参数类型';字符串';can';不能分配给参数类型';Uri';。而我';我是新来的
我试图用flutter插件HTTP发出一个httppost请求,但是我得到了一个标题错误。有人知道这是什么原因吗?因为在我的其他应用程序中,这工作得非常好Flutter 参数类型';字符串';can';不能分配给参数类型';Uri';。而我';我是新来的,flutter,dart,Flutter,Dart,我试图用flutter插件HTTP发出一个httppost请求,但是我得到了一个标题错误。有人知道这是什么原因吗?因为在我的其他应用程序中,这工作得非常好 import 'package:flutter/material.dart'; var this_year = DateTime.now().year.toString(); class AppConfig { static String copyright_text = "@ SaavaTech" + this_
import 'package:flutter/material.dart';
var this_year = DateTime.now().year.toString();
class AppConfig {
static String copyright_text = "@ SaavaTech" + this_year; //this shows in the splash
screen
static String app_name = "SaavaTech"; //this shows in the splash screen
//configure this
static const bool HTTPS = false;
//configure this
// static const DOMAIN_PATH = "192.168.0.106/ecommerce_demo";
static const DOMAIN_PATH = "shop.muwongehassan.com";
//static const DOMAIN_PATH = "adbuild.ae";
//do not configure these below
static const String API_ENDPATH = "api/v2";
static const String PUBLIC_FOLDER = "public";
static const String PROTOCOL = HTTPS ? "https://" : "http://";
static const String RAW_BASE_URL = "${PROTOCOL}${DOMAIN_PATH}";
static const String BASE_URL = "${RAW_BASE_URL}/${API_ENDPATH}";
//configure this if you are using amazon s3 like services
//give direct link to file like https://[[bucketname]].s3.ap-southeast-1.amazonaws.com/
//otherwise do not change anythink
static const String BASE_PATH = "${RAW_BASE_URL}/${PUBLIC_FOLDER}/";
}
我正在尝试从app_config.dart文件访问url链接使用:
final response = await http.post("${AppConfig.BASE_URL}/auth/signup",
headers: {"Content-Type": "application/json"}, body: post_body);
我想你是在用这个。自版本0.13以来,出现了。API已更改,现在接受url参数的Uri
对象,而不是String
。
仍然有很多过时的教程和帖子使用字符串而不是Uri
您可以创建一个Uri
,如下所示:
final response = await http.post(Uri.parse("${AppConfig.BASE_URL}/auth/signup"), headers: {"Content-Type": "application/json"}, body: post_body);
然后,在post
方法中使用它:
final url = Uri.parse("${AppConfig.BASE_URL}/auth/signup");
是的,我正在使用HTTPXPACKAGEDACK,它在某些情况下对我来说太多了,谢谢,我有很多链接来配置这些解决方案,可以很短的时间欢迎你,请考虑把它标记为你的问题的答案,谢谢!
final response = await http.post(
url,
headers: {"Content-Type": "application/json"},
body: post_body,
);