I'm trying to use Firebase to login, but I'm getting Type 'Null' is not a sub type of string as error when I try to parse _userId = responseData['localId'];
When I try to parse _token = responseData['idToken'];
, it works correctly.
responseData['localId']
is not NULL.
Here is full code:
class Auth with ChangeNotifier {
String? _token;
String? _userId;
Future<void> _authenticate(
String email, String password, String urlSegment) async {
var url = Uri.parse(
'https://www.google.com');
var body = json.encode({
'email': email,
'password': password,
'returnSecureToken': true,
});
try {
final response = await http.post(url, body: body);
final responseData = json.decode(response.body);
_token = responseData['idToken'];
_userId = responseData['localId'];
} catch (err) {
throw err;
}
}
Future<void> login(String email, String password) async {
return _authenticate(email, password, 'signInWithPassword');
}
}