【问题标题】:Flutter NoSuchMethodError颤振 NoSuchMethodError
【发布时间】: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


    【解决方案1】:

    String userId = await auth.createUserPatient(name, lastname... 中的 auth 似乎为空

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

    【讨论】:

    • 有一步我忘记将身份验证放在指向页面的函数标题上。现在这个问题已经解决了。谢谢
    【解决方案2】:

    在构建 Builder(dirty) 时引发了以下 NoSuchMethodError: 在 null 上调用了方法“>=”。收件人:空

    我收到了这个错误,似乎我已经为整个类声明了一个私有变量,但也(错误地)单独为同一个类中的一个方法声明了一个私有变量。删除第二个声明就成功了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 2020-10-14
      • 2020-09-21
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多