Flutter & Firebase App Tutorial #6 - Custom User Model

preview_player
Показать описание
Hey gang, in this tutorial we'll create a custom User model for our project, which contains only the data we need. This makes our user objects more suited to our purpose.
----------------------------------------

🐱‍💻 🐱‍💻 Course Links:

🐱‍💻 🐱‍💻 Other Related Courses:

Рекомендации по теме
Комментарии
Автор

UPDATES: 6/10/2021
Following one of the other comments, you rename the custom class User to something different. I renamed it to MyUser.

You may still get errors because Flutter is now null-safe. Before, a String could be String or null, now IT CAN ONLY BE STRING! (from what I understand) To get around this, you basically add a bunch of "?" and "!" Which one? I don't know I just try for both and hope it works.

SO: myuser.dart (IN VIDEO IT'S CALLED user.dart, but I renamed it)
class MyUser {
final String? uid;

MyUser({this.uid});
}
*make sure you add the "?"*

in auth.dart:
// create MyUser object based on User
MyUser? _userfromFirebase(User user) {
return user != null ? MyUser(uid: user.uid) : null;
}

//sign in anonymously
Future signInAnon() async {
try {
UserCredential result = await _auth.signInAnonymously();
User? user = result.user;
return _userfromFirebase(user!);
} catch (e) {
print(e.toString());
return null;
}
*MAKE SURE YOU NOTICE WHERE THERE ARE "!" AND "?"*

miscae
Автор

I am So Addicted to this Channel. I can't stop watching your tutorials. I am learning so much and i'm happy. Thank You Master!

dhanushg
Автор

This is my favorite series! Thank you so much. I'm learning a lot in isolation!

WesAHaque-ixco
Автор

thank you sir, for giving us the great lecture. This is the only channel which has a lots of things about firebase and flutter, I think none of the them have done a series like this. Thanks a lot and hats off to your work!!

prabhur
Автор

Great video series. Anxiously awaiting the next lesson. Keep up the great work!

vi-vffv
Автор

Another great tutorial! Can't wait for the next one :D

chriscarman
Автор

would be great if we could get an update to this series as it is now buggy with new flutter features and depreciation of other features.

neb
Автор

very beautifully explained with that presentation <3

hammadulaziz
Автор

Using models is always very helpful, but the newer Flutter version contains a User class by default from where you can fetch plenty of details about the user, so those who are watching this right now can skip this part, great series by the way!

kahanx
Автор

the best channel to learn flutter... thanks!

SofianMW
Автор

I really like your tutorials cuz you give away valuable knowledge.

armagangok
Автор

Those running flutter after August 2020 may encounter this error :

[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

If that happens add this to your dependencies:

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
firebase_auth: ^0.18.4+1
cloud_firestore: ^0.14.4
firebase_core : ^0.5.0


And replace the entire main function with:

void main() async {

await Firebase.initializeApp();
runApp(MyApp());
}

Have a nice day! :)

pranavbhat
Автор

very easy to understand, thank you very much

kronkdark
Автор

Great video tutorial series. It is clear and concise. Thank you. Can't wait for the next lesson.

MarkRonnelCamilon
Автор

Creating this Custom User class is an optional step. You can skip this step if you want!
PS: The instructor has said this in the next video at the end.

nareshshewkani
Автор

If your result is showing an instance of user and you wanna know which data is included in the instance, you can use "inspect(user);" instead of "print(user);"

w
Автор

U have a very good way of teaching gradually and explicitly but there were something I couldn't wrap my head around on around minute 4 you made a User type function and you passed a FirebaseUser instead of a String that you defined in the constructor.

travelfoodbusinessbestheyyono
Автор

the best teacher ever, altho out of curiosity why create another method just to return a user instance... why not return our ternary expression from the first method. altho we know the first method returns null only if it wents to the try-catch block we also know if it is in try-catch it will return null and the new method won't even be called. am just trying to figure out if I miss anything.

webdev
Автор

I really love this tutorial but I wanted to know how you call multiple models in your stream? Since your stream provider has to be an ancestor to any widget.

NanaZimmerUCLEAR
Автор

E/flutter ( 8289): Unhandled Exception: NoSuchMethodError: Class 'User' has no instance getter 'id'.
what does that mean ?

mido