Advanced Provider Tutorial - Part 1: Project Setup & Authentication Flow

  Рет қаралды 34,329

Andrea Bizzotto

Andrea Bizzotto

Күн бұрын

Sign up here for more updates: 👇👇
codewithandrea.com/
LEVEL: INTERMEDIATE / ADVANCED
This multi-part tutorial shows how to use Provider to build an app that lets the user choose and upload an avatar image to Firestore.
- We will start from a sample project which already contains some widgets and services.
- We will see how to use Provider to connect things together.
- We will learn how to setup an architecture that supports more complex applications.
FULL SOURCE CODE 👇👇
github.com/bizz84/firebase_us...
HIGHLIGHTS
00:00 - Intro
00:28 - Application architecture and overview
01:17 - Tutorial overview
02:45 - Demo app overview
04:00 - GitHub code & project setup
05:33 - Let's code
07:22 - Firebase authentication service: overview and usage
09:49 - Conditional authentication logic
13:06 - Wrap up
Want more? Check out all my Flutter courses: 👇👇
codewithandrea.com/courses/
Thanks for watching!

Пікірлер: 68
@curiousnrd
@curiousnrd 4 жыл бұрын
This is fantastic! Thank you for the hard work. I look forward to the rest of the series!
@yassinyoussoufali6324
@yassinyoussoufali6324 4 жыл бұрын
You really explain things well. Can't wait for the next episodes :)
@blisteredoutlaw1993
@blisteredoutlaw1993 4 жыл бұрын
I just wanna say I am very thankful that I saw your channel. Out of all the channels I am subscribed, you are one of the top 5 if not the best channel teaching flutter! In my opinion, lots of the technique you have used (mostly on advance tuts) can be considered production grade and some just need some few tweaks and they are ready to go! Just so you know, I subscribes to many channels teaching flutter just to keep updated about it. But, for some reasons, I never really delve into it. Your teachings are one of the reason I will be studying flutter now. I look forward for more of your videos . Thanks Andrea! :)
@dl88889
@dl88889 4 жыл бұрын
I just signed up for your REST API course on your website. Can't wait to get started. Thank you for putting up all these great resources!
@rasmustchristensen
@rasmustchristensen 4 жыл бұрын
Perfect once again. I already have provider and Firebase Auth in the app I'm building, but learned a few tips I'll refactor to improve!
@findsarfaraz
@findsarfaraz 3 жыл бұрын
Great... tutorial... . you people make internet a better place
@techyeunoia9414
@techyeunoia9414 3 жыл бұрын
just starting out with flutter and I'm already thankful you exist and make these tutorials
@goddardpk
@goddardpk 3 жыл бұрын
Andrea, thanks for concise and informative examples! This 14 minute segment is priceless!
@JimmyCheng
@JimmyCheng 4 жыл бұрын
great work man, you are wonderful!
@andreykotkovets6868
@andreykotkovets6868 4 жыл бұрын
Great, Andrea. I see the light at the end of ProviderUnderstanding tunnel ;)
@sk8sbest
@sk8sbest 4 жыл бұрын
great comment
@AndreClements
@AndreClements 2 жыл бұрын
wow, it's architecture is so elegant :-)
@isurujn
@isurujn 2 жыл бұрын
I appreciate the effort you put into your tutorials. As someone who learns by visualising, your charts/graphs of the overall system really helps. Thank you 🙏🏼
@moses995
@moses995 4 жыл бұрын
You're amazing at what you do
@DrSndan
@DrSndan 4 жыл бұрын
Thank you for this wonderful tutorial
@mual77
@mual77 4 жыл бұрын
WOW!! Thanks a lot.
@user-gt4je7vi9w
@user-gt4je7vi9w 4 жыл бұрын
magnificent!!!
@adammusaali4906
@adammusaali4906 4 жыл бұрын
Thank's so much for this tutorial,that god help you
@infinitezymalny
@infinitezymalny 4 жыл бұрын
look out which version of provider u use, according to documentation in v4.x.x: The parameters builder and initialBuilder of providers are removed. initialBuilder should be replaced by create. builder of "proxy" providers should be replaced by update builder of classical providers should be replaced by create
@kirill4531
@kirill4531 4 жыл бұрын
That's what I was waiting for! Great. Subscribed and turned notifications ON! I'm excited because of the announced future optimization of the architecture and the proper approach which you will show us at the end of this series. !!! Also please don't forget to show how to handle gracefuly errors which may arise in services (auth/user/data/etc.) and how to consume them in the UI (a snackbar or a dialog)
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
Sure, next video is coming next week. Re. handling errors - the videos already show try/catch blocks where appropriate. The simplest thing is to show a dialog inside the catch (this is easy to do, also covered in detail in my paid course).
@kirill4531
@kirill4531 4 жыл бұрын
@@CodeWithAndrea Andrea Bizzotto try/catch handling is for services and ViewModel layer, whereas in the UI you want to show corresponding dialogs to the user. And the question is how do you do that. What I do: is I have a Stream in my ViewModel and in the UI I listen to that stream and show snackbars or dialogs on each portion of data
@faisalahmed1981
@faisalahmed1981 4 жыл бұрын
good one
@macdon2351
@macdon2351 4 жыл бұрын
Thank you
@graphiclife5416
@graphiclife5416 4 жыл бұрын
Great! Finally one propper tutorial with the Provider and Firestore. It would be nice if you also create a users collection for user details like most apps do. And please show us how to create a stream without streambuilder in custom class with ChangeNotifier and how to dispose stream. I'm super excited for your future tutorials! Thank you!
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
Thanks. There's nothing wrong with streams per-se. If you use a 3rd party API that gives you streams (e.g. Firebase auth, Firestore), then StreamBuilder/StreamProvider is the way to go. I normally only use ChangeNotifier/ChangeNotifierProvider for local application state. But yes, a lot of this is a good topic for future tutorials.
@graphiclife5416
@graphiclife5416 4 жыл бұрын
@@CodeWithAndrea What if you need data from the Firestore on multiple screens but you don't need to display them, do you still use StreamBuilder? I also bought your Flutter course on Udemy I found yesterday. I hope your course is different because all the courses I found are showing how to create StreamBuilder and display data right away. I need one tutorial for initiating the stream > manipulating stream data > making data globally available across the app. Or even better: initiating 2 streams > combing and manipulating stream data > and making data globally available.
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
Graphiclife you can manipulate stream data inside a Bloc if you want. My course shows how to work with stream subscriptions, create and manage streams in Blocs, and combine multiple streams with RxDart.
@Linxy
@Linxy 4 жыл бұрын
Thanks, absolutely fantastic, the best!! You are 1000000000x better than fireship
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
Linxy Thank you. I get a lot of inspiration from Fireship. Glad my videos are useful
@MasatoNakada1
@MasatoNakada1 4 жыл бұрын
Thanks Andrea for an awesome video! Quick question. Why did you use stream to track authentication and not changeNotifyProvider?
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
ChangeNotifierProvider works with objects that implement ChangeNotifier. Streams don't. So it's easier to just use a StreamBuilder in this case.
@MasatoNakada1
@MasatoNakada1 4 жыл бұрын
Andrea Bizzotto thx for the response and my bad! My question should be, why did you use stream instead of changeNotifier? I recall that you refactored to changeNotifier on your Udemy course..
@themindstorm9947
@themindstorm9947 4 жыл бұрын
@@MasatoNakada1 even I was confused as to why a streamBuilder had to be used. I thought that by referencing something from the service, the widget would automatically rebuild itself on a change. Did you find the answer?
@MasatoNakada1
@MasatoNakada1 4 жыл бұрын
TheMindstorm from what I understand today, since Firebase_auth only gives you the Stream of FirebaseUser, you have to first use that to get the User class. Once you do that, you can add that value to a Privider and expose that to the widget tree under it. Well I maybe completely wrong though 🤫
@icalculi
@icalculi 4 жыл бұрын
regarding signout, @12:50 should i make the provider to listen false?
@dhruvkelawala960
@dhruvkelawala960 4 жыл бұрын
Can you share the desktop wallpaper?
@themindstorm9947
@themindstorm9947 4 жыл бұрын
For managing authState, why do you use a streamBuilder? Is not not suitable to use a Consumer()? Other than that, I understood everything, great tutorial!
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
You need something that can consume a Stream. So either a StreamBuilder or a StreamProvider.
@fumesmaispasque
@fumesmaispasque 4 жыл бұрын
Thanks you, which "indent extension" do you use please ? and can you list all yours VsCode extensions
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
I listed all my extensions here: kzbin.info/www/bejne/q3eYo4NoiriDbaM
@seanthomas9398
@seanthomas9398 4 жыл бұрын
Thanks for this video! In the AuthWidget, does "listing: false" do anything? It looks like the FirebaseAuthService isn't a ChangeNotifier, and that the only way we can get updates is via the StreamBuilder.
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
In theory, I agree with you. In practice, I have observed an issue where unwanted widget rebuilds were taking place when pushing routes IF the AuthWidget is a descendant of MaterialApp. This should not be a problem if you use the code from Advanced Provider Tutorial 3.
@strikeoffate
@strikeoffate 3 жыл бұрын
will the whole thing be updated to null safety? In Avatar Reference i get error, that it can't return Null
@puspanjalimohapatra7560
@puspanjalimohapatra7560 3 жыл бұрын
Hii, my homepage is extended to statefullwidget , everytime if i pressed button or using Textformfield to input text ,streambuilder is building the homepage again .pls give me a solution
@Bathusaix
@Bathusaix 4 жыл бұрын
Hi Andrea .. I love your tutorials .. A query here in this project there is no user creation? that is to say the method of firebas e to create users? in the atuh services I don't see that method
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
Nestor Marquez when you sign in anonymously, Firebase creates a new user.
@Bathusaix
@Bathusaix 4 жыл бұрын
@@CodeWithAndrea I mean the method createUserWithEmailAndPassword is not in this project right?
@BrianAkaBear
@BrianAkaBear 4 жыл бұрын
How do you correct error: flutter Exception has occurred. FormatException (FormatException: Unexpected character (at character 1) ^ ) when parsing json?
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
Looks like you're trying to parse HTML as JSON. That won't work. Would be best to fix your backend API and ensure it always returns JSON.
@rizi619
@rizi619 4 жыл бұрын
what kind of changes do we need if we want to this with REST api, rather than firebase
@NatoBoram
@NatoBoram 4 жыл бұрын
You need an existing back-end. Then, using the same services, just send a HTTP Post request to said back-end and return its value in a Future.
@garethbeall3674
@garethbeall3674 4 жыл бұрын
Is there a Provider version of StreamBuilder?
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
Gareth Beall yes, it’s called StreamProvider. I’ll cover it in future videos, but you can look up the documentation for now.
@rikyriky966
@rikyriky966 4 жыл бұрын
A great video again, as always. Do you know how to access a provider of an instance of widget class from the next route? For example, I have a provider class named “PostPVD” which I use as the state controller of a presentation widget class named “PostScreen”. PostPVD is used in every instance of the PostScreen as a controller by using a variable “postPVD”. There is another presentation widget class named “PostEditScreen”. Users can navigate to PostEditScreen from PostScreen back and forth. I want to have an access to that “postPVD” inside of PostEditScreen and make two routes share the exact same instance of postPVD. I actually find a way and will edit this comment as soon as I get my hands on my laptop. I pass the postPVD as a parameter to the PostEditScreen and consume it. So they share the same provider instance. In other words they share the same controller.
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
Provider can work with multiple routes, as long as your providers are ancestors of the MaterialApp. I'll cover this in detail in upcoming videos. But for now you can check the finished source code: github.com/bizz84/firebase_user_avatar_flutter/tree/optimized-implementation
@rikyriky966
@rikyriky966 4 жыл бұрын
Andrea Bizzotto Huge thanks for sharing the complete repo Andrea. I think it may not work if I declare the providers by wrapping the root of my app. Because they are now available fir the rest of the widget tree. So every other widget use the same provider as the state controller. Btw, AuthProvider, StyleProvider, LocalizationProvider, BasketProvider etc. are the ones that all the widget tree must have an access. So I declare them inside a MultiProvider by wrapping the root of my app widget, as you suggest. However, I really needed individual providers that are solely available for each new instance of a widget or route. Separately and independently from each other. In order to make these type of state controlling, I instead declare them inside the corresponding widget so only that instance of the widget has access to that particular provider. If I want to make that provider to the next route, I pass the “provider” and the “context” to the next routes as constructor parameters. So the declared provider can be consumed by the Consumer widget in the next route. There is no need for you to reply and it’s totally OK. It’s just me wanted to write a few of my opinions :)
@CodeWithAndrea
@CodeWithAndrea 4 жыл бұрын
@@rikyriky966 Yes, if you need individual providers, then they don't go at the root of the widget tree. In this scenario, I normally inject the dependencies that I need to the constructor of the widgets presented inside routes. This way I don't have to hold on to other widgets' contexts.
@AnvildevilGq00
@AnvildevilGq00 4 жыл бұрын
a lot of code from netninja
@johndavedecano2438
@johndavedecano2438 4 жыл бұрын
why people always assume that were always be using firebase?
@techcsnerd1328
@techcsnerd1328 3 жыл бұрын
yess.. There should be more tutorials on Flutter plus NodeJs/PHP
@theascendunt9960
@theascendunt9960 2 жыл бұрын
@@techcsnerd1328 That's not the point of this tutorial. The exact tech stack you use in the backend shouldn't matter to learn Provider. If you learn to do it with Firebase, you should be able to learn how to do it with other tech stacks on your own. Stop relying on spoonfeeding.
@phamquang9217
@phamquang9217 2 жыл бұрын
FirebaseUser changed to User AuthResult changed to UserCredential GoogleAuthProvider.getCredential() changed to GoogleAuthProvider.credential()
I Never Want To Build Authentication Any Other Way
2:03:20
Elliott Chong
Рет қаралды 17 М.
Little girl's dream of a giant teddy bear is about to come true #shorts
00:32
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,4 МЛН
Они так быстро убрались!
01:00
Аришнев
Рет қаралды 1,5 МЛН
Starter Architecture for Flutter & Firebase Apps
19:41
Andrea Bizzotto
Рет қаралды 40 М.
Flutter Provider - Advanced Firebase Data Management
11:08
Fireship
Рет қаралды 143 М.
Complete Flutter Architecture using Provider and Stacked
22:59
FilledStacks
Рет қаралды 90 М.
Pragmatic State Management in Flutter (Google I/O'19)
33:25
Flutter
Рет қаралды 448 М.
Top 16 Dart Tips and Tricks Every Flutter Developer Should Know
11:44
Andrea Bizzotto
Рет қаралды 59 М.
Top 12 Flutter Tips & Tricks
9:32
Fireship
Рет қаралды 266 М.
Flutter State Management - The Grand Tour
14:07
Fireship
Рет қаралды 239 М.
Implementing complex UI with Flutter - Marcin Szałek | Flutter Europe
44:26
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 28 МЛН
iPhone 15 Pro Max vs IPhone Xs Max  troll face speed test
0:33
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 63 МЛН
Better Than Smart Phones☠️🤯 | #trollface
0:11
Not Sanu Moments
Рет қаралды 16 МЛН
Опасность фирменной зарядки Apple
0:57
SuperCrastan
Рет қаралды 11 МЛН