flutter - The argument type 'String' can't be assigned to the parameter type 'Uri' 'Uri' is from 'dart:core'. final response = await http.post(url,
问题描述
when I run my flutter app I will get this kind of error.
The argument type 'String' can't be assigned to the parameter type 'Uri'.
- 'Uri' is from 'dart:core'. final response = await http.post(url,
here is my .dart file , code where the Error occured.
import 'dart:convert';
import 'dart:html';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'package:provider/provider.dart';
import 'package:save_geez/LoginAndSignupScreen/signup_page.dart';
class Authentication with ChangeNotifier {
Future<void> Signup(String email, String password) async {
const url =
'https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=AIzaSyAnhSx2zHOr0FO9qV-GBXizFg9sy4jz7dw';
final response = await http.post(url,
body: json.encode({
'email': email,
'password': password,
"returnSecureToken": true,
}));
final responseData = json.decode(response.body);
print(responseData);
}
}
^
解决方案
Please use this, it willsolve your problem:
Uri url =Uri.parse('https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=AIzaSyAnhSx2zHOr0FO9qV-GBXizFg9sy4jz7dw');
The post
method now uses a Uri
object, and not a string. Same thing for get, put, delete
..etc
Parse it as a Uri
and pass the Uri object, as in the code snippet above. And keep everything else the same as it is, and things should work fine.
推荐阅读
- powershell - 将类型字符串转换为安全字符串
- ksqldb - 使用 group by 和 latest_by_offset 查询物化视图两次返回相同的键
- json - Postgresql group by query 转换 json 格式
- angular - 骆驼案例中的gRPC json数据
- macos - 为什么自制软件需要 /usr/local/share/man/man8 的权限
- javascript - 字符串没有在 javscript 中使用双引号打印?
- javascript - 如何在 react.js 中显示同一项目和不同日期的值的总和
- .net - 注册层失败:重新执行错误:退出状态 1:输出:hcsshim::ProcessBaseLayer \\?\D:\docker\windowsfilter\...:访问被拒绝
- ios - 从照片库中选择多个视频时 iOS 应用程序崩溃 - 内存警告
- node.js - “无法发送空消息”