gpt4 book ai didi

firebase - flutter NoSuchMethodError

转载 作者:IT王子 更新时间:2023-10-29 07:22:43 25 4
gpt4 key购买 nike

我正在尝试使用几个类来使用函数。

在第一个中,我有以下内容:

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');
}...
}

auth.dart 中有函数createUserPatient 的页面如下:

 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): 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", "test@program.com", "prueba1", 3)

如您所见,没有向函数发送空值。我似乎无法解决这个问题。

最佳答案

String userId = await auth.createUserPatient(name, lastname...

中似乎 auth 为 null

尝试调试您的应用并检查 auth 是否为 null

关于firebase - flutter NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54793188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com