【发布时间】:2019-07-14 13:07:47
【问题描述】:
我正在尝试使用几个类来使用函数。
在第一个中,我有以下内容:
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 页面中的一个函数,它没有显示任何问题,但是函数 await auth.createUserPatient(name, lastname, rut,birthdate,gender, region, comune, city, street, number, block, phone, mail, password , 轮廓);在第一个代码中给了我错误
I/flutter (31347):错误:NoSuchMethodError:方法 在 null 上调用了“createUserPatient”。
I/flutter (31347):接收器:null
I/flutter (31347):尝试调用:createUserPatient("Andres", “Urrutia”、“3343434323”、“23/5/2015”、“M”、“F85XtvnJlJRnuynhkHAR”、 “16P7Gp6JKp8vQGouCOiH”,“独立”,“Av Pocuro”,“33”,“98”, "565465456", "test@program.com", "prueba1", 3)
如您所见,没有向函数发送 null 值。我似乎无法解决这个问题。
【问题讨论】:
标签: firebase flutter firebase-authentication