Reputation: 147
I am trying to use a couple of classes to use functions.
In the first one I have the following:
import 'package:flutter/material.dart';
import 'auth.dart';
import 'state_rut.dart';
class SelectProfile extends StatelessWidget{
SelectProfile({this.auth, this.onSignedIn, this.name, this.lastname,
this.rut, this.birthdate, this.gender, this.region, this.comune, this.city, this.street, this.number, this.block, this.phone, this.mail, this.password});
final BaseAuth auth;
final VoidCallback onSignedIn;
final String name, lastname, rut, birthdate, gender, region, comune, city, street, number, block, phone, mail, password;
void createuser() async{
try{
String userId = await auth.createUserPatient(name, lastname, rut, birthdate, gender, region, comune, city, street, number, block, phone, mail, password, profile);
onSignedIn();
}catch(e){
print('Error: $e');
}...
}
The page auth.dart which has the function createUserPatient goes as follows:
import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
abstract class BaseAuth {
Future<String> signInWithEmailAndPassword(String email, String password);
Future<String> createUserWithEmailAndPassword(String email, String password);
Future<String> createUserPatient(String name, String lastname, String rut, String birthdate, String gender, String region, String comune, String city, String street, String number, String block, String phone, String mail, String password, int profile);
Future<String> createUserProfessional(String name, String lastname, String rut, String birthdate, String gender, String region, String comune, String city, String street, String number, String block, String phone, String mail, String password, int profile, String speciality, String creditcard);
Future<String> currentUser();
Future<void> signOut();
}
class Auth implements BaseAuth {
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
Future<String> signInWithEmailAndPassword(String email, String password) async {
FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
return user.uid;
}
Future<String> createUserWithEmailAndPassword(String email, String password) async{
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
return user.uid;
}
Future<String> currentUser() async{
FirebaseUser user = await _firebaseAuth.currentUser();
return user.uid;
}
Future<String> createUserPatient(String name, String lastname, String rut, String birthdate, String gender, String region, String comune, String city, String street, String number, String block, String phone, String mail, String password, int profile) async{
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: mail, password: password);
if(user.uid != null){
final address = await Firestore.instance.collection('address').document()
.setData({
'region': region,
'comune': comune,
'city': city,
'street': street,
'number': number,
'block': block,
'user_id': user.uid
});
final new_user = await Firestore.instance.collection('user').document()
.setData({
'names': name,
'last_names': lastname,
'rut': rut,
'birth_date': birthdate,
'gender': gender,
'mail': mail,
'phone': phone,
'user_type': profile,
'user_id': user.uid
});
}
return user.uid;
}...
}
I have another class which goes in another page with the function String userId = await widget.auth.signInWithEmailAndPassword(_email, _password); which is a function in the auth.dart page which shows no issues, but the function await auth.createUserPatient(name, lastname, rut, birthdate, gender, region, comune, city, street, number, block, phone, mail, password, profile); in the first code gives me the error
I/flutter (31347): Error: NoSuchMethodError: The method 'createUserPatient' was called on null.
I/flutter (31347): Receiver: null
I/flutter (31347): Tried calling: createUserPatient("Andres", "Urrutia", "3343434323", "23/5/2015", "M", "F85XtvnJlJRnuynhkHAR", "16P7Gp6JKp8vQGouCOiH", "Independencia", "Av Pocuro", "33", "98", "565465456", "[email protected]", "prueba1", 3)
As you can see there are no values null sended to the function. I cant seem to get around the issue.
Upvotes: 1
Views: 4556
Reputation: 21
The following NoSuchMethodError was thrown building Builder(dirty): The method '>=' was called on null. Receiver: null
I received this error and it seems I had declared a private variable for a class as a whole but also (by mistake) ,separately for a method inside the same class. Removing that second declaration did the trick.
Upvotes: 1
Reputation: 369
It seems that auth is null in String userId = await auth.createUserPatient(name, lastname...
Try to debug your app and check if auth is null
Upvotes: 3