Reputation: 85
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'.
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);
}
}
^
Upvotes: 1
Views: 2077
Reputation: 1323
You have to pass the Uri instead of String. you can convert String
to Uri
Uri url = Uri.parse("https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=AIzaSyAnhSx2zHOr0FO9qV-GBXizFg9sy4jz7dw");
Upvotes: 0
Reputation: 12353
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.
Upvotes: 3