qtn that now clear for the error i was facing in the question that ii asked. debug console return _auth.authStateChanges.map(_userfromFirebaseUser);

Viewed 21

error on the map methoddebug console

auth.dart:

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:lewandowski/models/bro.dart';

class AuthService{
  // method to sign in anon
  final FirebaseAuth _auth = FirebaseAuth.instance;

  Bro? get bro => null;
  // create an object based on firebaseuser
  Bro? _userfromFirebaseUser(Bro user){
    return User != null ? Bro(uid:user.uid) : null;
  }
// change user stream

    Stream<Bro> get user {
    return _auth.authStateChanges.map(_userfromFirebaseUser);
  }
  Future signAnon() async {
    try {
      UserCredential result = await _auth.signInAnonymously();
      User? user = result.user;
      return user;
    }
    catch (e) {
      print(e.toString());

      return null;
    }
  }


  // method to sign in with email and password

  // method to sign up with email and password

  //method to sign out
Future signOut() async{
    try{
      return await _auth.signOut();
    }
    catch(e){
      print(e.toString());
    }
    return null;
}

}

Error in debug console:

Launching lib\main.dart on TECNO K7 in debug mode...
Running Gradle task 'assembleDebug'...
lib/services/auth.dart:17:35: Error: The method 'map' isn't defined for the class 'Stream<User?> Function()'.
 - 'Stream' is from 'dart:async'.
 - 'User' is from 'package:firebase_auth/firebase_auth.dart' ('../flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-3.9.0/lib/firebase_auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'map'.
    return _auth.authStateChanges.map(_userfromFirebaseUser);
                                  ^^^

FAILURE: Build failed with an exception.

  • Where: Script 'E:\Development\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1156

  • What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command 'E:\Development\flutter\bin\flutter.bat'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

BUILD FAILED in 3m 48s Exception: Gradle task assembleDebug failed with exit code 1

Appreciate if someone can advise. Thank you in advance!

1 Answers

The authStateChanges is not a property but a function.

Try updating it to

Stream<Bro?> get user {
    return _auth.authStateChanges().map(_userfromFirebaseUser);
}

Also the return doesn't seems to be right to me. You are mapping via method thats accepting wrong argument. You want to have User? as a parameter of your method _userfromFirebaseUser

Related