londonappbrewery / flash-chat-flutter

Learn to Code While Building Apps - The Complete Flutter Development Bootcamp
https://www.appbrewery.co
195 stars 676 forks source link

183. Registering Users with Firebase using FirebaseAuth #36

Open Aatashh opened 3 years ago

Aatashh commented 3 years ago

code is exactly matched with the lesson but these two errors came out of nowhere:-

lib/screens/chat_screen.dart:14:3: Error: Type 'FirebaseUser' not found. FirebaseUser loggedInUser; ^^^^^^^^^^^^ lib/screens/chat_screen.dart:12:7: Error: The non-abstract class '_ChatScreenState' is missing implementations for these members:

class _ChatScreenState extends State { ^^^^^^^^^^^^^^^^ /C:/flutter/packages/flutter/lib/src/widgets/framework.dart:1428:10: Context: 'State.build' is defined here. Widget build(BuildContext context); ^^^^^ lib/screens/chat_screen.dart:14:3: Error: 'FirebaseUser' isn't a type. FirebaseUser loggedInUser; ^^^^^^^^^^^^

Aatashh commented 3 years ago

image

Aatashh commented 3 years ago

somebody help!!!

ghost commented 3 years ago

use User instead of FirebaseUser

Aatashh commented 3 years ago

Thanks Nawab that is fixed now searching for _ChatScreenState

shivamkg0604 commented 3 years ago

After firebase_auth version 0.18.0

Few breaking updates were made in firebase_auth 0.18.0. FirebaseUser is now called User, currentUser is a getter, and currentUser is synchronous.

This makes the code: class _ChatScreenState extends State { final _auth = FirebaseAuth.instance; User loggedInUser;

@override void initState() { super.initState(); getcurrentuser(); }

void getcurrentuser() { try { final user = _auth.currentUser; if (user != null) { loggedInUser = user; print(loggedInUser.email); } } catch (e) { print(e); } }

Before firebase_auth version 0.18.0

email is a property of FirebaseUser object. Since auth.currentUser() return a future, you have to await in order to get the user object.

Aatashh commented 3 years ago

After firebase_auth version 0.18.0

Few breaking updates were made in firebase_auth 0.18.0. FirebaseUser is now called User, currentUser is a getter, and currentUser is synchronous.

This makes the code: class _ChatScreenState extends State { final _auth = FirebaseAuth.instance; User loggedInUser;

@override void initState() { super.initState(); getcurrentuser(); }

void getcurrentuser() { try { final user = _auth.currentUser; if (user != null) { loggedInUser = user; print(loggedInUser.email); } } catch (e) { print(e); } }

Before firebase_auth version 0.18.0

email is a property of FirebaseUser object. Since auth.currentUser() return a future, you have to await in order to get the user object.

Thank you Shivam!

sulavchhetri commented 3 years ago

After firebase_auth version 0.18.0

Few breaking updates were made in firebase_auth 0.18.0. FirebaseUser is now called User, currentUser is a getter, and currentUser is synchronous.

This makes the code: class _ChatScreenState extends State { final _auth = FirebaseAuth.instance; User loggedInUser;

@override void initState() { super.initState(); getcurrentuser(); }

void getcurrentuser() { try { final user = _auth.currentUser; if (user != null) { loggedInUser = user; print(loggedInUser.email); } } catch (e) { print(e); } }

Before firebase_auth version 0.18.0

email is a property of FirebaseUser object. Since auth.currentUser() return a future, you have to await in order to get the user object.

Thank you so much!!

sulavchhetri commented 3 years ago

In the exact same lesson, Please help while using modal progess hud so that it doesn't spin while the password and email are not entered and i click on login button but only spin when the user email and password are entered Roundbutton( title: 'Log In', onPressed: () async { setState(() { showSpinner= true; }); try{ final user = await _auth.signInWithEmailAndPassword(email: email, password: password); Navigator.pushNamed(context, ChatScreen.id); setState(() { showSpinner= false; }); } catch(e){ print(e); } }, ),