我正在尝试使用几个类来使用函数。
在第一个中,我有以下内容:
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');
}...
}
具有功能createUserPatient的页面auth.dart如下:
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;
}...
}
我有另一个类,该类在另一页中具有功能String userId = await widget.auth.signInWithEmailAndPassword(_email,_password);这是auth.dart页面中的一个函数,该函数不显示任何问题,但是该函数正在等待auth.createUserPatient(名称,姓氏,车辙,生日,性别,地区,公社,城市,街道,数字,街区,电话,邮件,密码,个人资料);在第一个代码中给我错误
I / flutter(31347):错误:NoSuchMethodError:该方法 在null上调用了“ createUserPatient”。
I / flutter(31347):接收方:空
I / flutter(31347):尝试调用:createUserPatient(“ Andres”, “ Urrutia”,“ 3343434323”,“ 23/5/2015”,“ M”,“ F85XtvnJlJRnuynhkHAR”, “ 16P7Gp6JKp8vQGouCOiH”,“独立”,“ Av Pocuro”,“ 33”,“ 98”, “ 565465456”,“ test@program.com”,“ prueba1”,3)
如您所见,没有值发送给该函数。我似乎无法解决这个问题。
答案 0 :(得分:1)
似乎String userId = await auth.createUserPatient(name, lastname...
中的auth为空
尝试调试您的应用并检查auth是否为空
答案 1 :(得分:1)
在构建Builder(dirty)时引发了以下NoSuchMethodError: 方法'> ='在null上被调用。接收者:null
我收到此错误,似乎我已经为整个类声明了一个私有变量,但也为同一类中的一个方法分别声明了(错误)。删除第二个声明就可以了。