Flutter - BuildContext Explained For Beginners (+ Bonus: How To Use SnackBar)

preview_player
Показать описание
If you're unsure of what the BuildContext is, then this is the video that will clear your doubts.

The concept of BuildContext itself is actually very simple: it lets the widgets (that need it) know where in the widget tree they are placed, so that they can do its function correctly.

But sometimes, you need to pass on a different context than the one in the arguments of the build method. And this video should clear your doubts right up.

If you still don't know what it is at the end of the video, watch it again! And I promise it'll click for you.

It is definitely a must to be able to understand what BuildContext is and how you should use it in your Flutter journey. So, click that play button and drop a like if you understand the BuildContext after this video tutorial!

00:00 - Intro
00:27 - Showing UI/Code
00:40 - BuildContext Class Documentation
01:22 - Basic Explanation (With Analogy)
01:37 - Summing It Up
02:04 - Explaining It Using a Widget Tree
02:46 - Explaining The Documentation Example
03:14 - Using BuildContext
04:53 - Making The SnackBar Work
07:10 - Like & Subscribe
07:18 - Flutter Mentor Out

#BuildContext #Flutter #SnackBar

Credits:

Drunk Man Image:

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

Meanwhile, with Flutter 2.0 the SnackBar code updated. This is how to invoke the showSnackBar method in Flutter 2.0 (my next video is about this kind of deprecations):



(Yes, basically just add "Messenger" after "Scaffold")

FlutterMentor
Автор

Thanks man! Surprisingly few explanations of this out there! Watching the pros bashing out builders under widgets without knowing why finally makes sense. Nice one.

Mark-mobo
Автор

wow! Hard concept to grasp. I watched 5 videos prior this one and i got more confused if anything ... your video was a revelation. Thank you ... not so hard when thigs are well explained. Truly thank you, fantastic video great explanation!

leleemagnu
Автор

Ty, muito obrigado! me ajudou demais a entender o conceito de context!!!!

mavie--
Автор

its pretty good thank you for making this

erfansoltanzadeh-ux
Автор

The following assertion was thrown while handling a gesture:
Navigator operation requested with a context that does not include a Navigator.

The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.
When the exception was thrown, this was the stack:

how to resolve this error

aravindhkumar
Автор

Hello and thank you for your explanations. So as I have clearly understood it, if a snackbar to work on first scaffold, it should not call scaffold.of(context) as it is calling on the scaffold itself, unless it is located in subtree beneth.

danielhalmstrand
Автор

I had some confusion.first every widget has its own context like scaffold, material app, elevated button etc.I understand that context are just to know where I am on this widget tree like myapp-> etc. My app class becomes widget while instantiated right? And do every widget has build method for example scaffold widget has build method.And finally where do we use class build method context inside the widget tree.If it doesn't work for snackbar then what is the usecase of this context.Its just a parent context (top-level) of all context

skirllexrude
Автор

That’s a more practical example. I appreciate it. But there’s too much I can’t understand lol.

MachineLearning-rwjd
Автор

I 've just tried to do print(' ${context.toString()} '). Funny.

fredgotpub