get_it (Package of the Week)

  Рет қаралды 132,954

Flutter

Flutter

Күн бұрын

Learn more about get_it → goo.gle/3HZugEA
If you've ever had to organize non-widget resources like data repositories or network connections, you know how much of a challenge it can be. Have no fear - `get_it` is here!
This video is also subtitled in Chinese, Indonesian, Italian, Japanese, Korean, Portuguese, and Spanish.
Talk from the get_it author → goo.gle/3f39w2c
Follow Thomas on Twitter → goo.gle/3HEpM60
Learn everything about Flutter at → goo.gle/2WAhEN1
Get more tips → goo.gle/Flutte...
Subscribe to Flutter! → goo.gle/FlutterYT
#PackageoftheWeek #Widgets #Flutter

Пікірлер: 112
@deeplight1417
@deeplight1417 2 жыл бұрын
For those who wonder what's the purpose of this library, the main usage is for dependency injection (like in Spring for example). It has most of the functionnalities required to do that.
@paucolome4298
@paucolome4298 2 жыл бұрын
For angular devs this is a blessing
@CryptoWulf_app
@CryptoWulf_app 2 жыл бұрын
@@paucolome4298 The example shows how to get a bloc. You could just use repository provider for your services and blocprovider for your bloc and dont need an extra dependency/get_it.
@allphredo
@allphredo 2 жыл бұрын
I don't get it :(
@dkdanish8143
@dkdanish8143 11 ай бұрын
I recommend first understand about dependency injection and service locator which are popular patterns used in software development.
@thesunstep
@thesunstep 5 күн бұрын
@@dkdanish8143 Breuh I think u missed the joke
@rajveersingh2056
@rajveersingh2056 2 жыл бұрын
Get_it explanation is incomplete without a pun and saying "get it?" at the end
@maxc9432
@maxc9432 Жыл бұрын
we need a remake hahaha
@ByHassanBasri
@ByHassanBasri 2 жыл бұрын
well this is the first time , i didn't understood anything by watching your video (otherwise I have learned something from every package video ,) like what is the benefit and why to use it? other videos are very helpful may be the narrator and producer has changed ?
@michasengotta2295
@michasengotta2295 2 жыл бұрын
You know how Providers reach dependencies down the widget tree and whenever you need something, you can use a Consumer to retrieve that thing from the BuildContext? Sometimes you don't have a context at hand (for example inside a service method) and some things don't even care about their location in the tree. So why would you reach them down the widget tree? Simply put: You don't have to. That's where get_it is super helpful! You can just get the thing anywhere, because it's a singleton (which means there is just one of it's type). What they call dependency injection (DI) is just a fancy word for not having to reach concrete stuff around, but instead automatically getting the things you need at runtime, so you can mock them easily for testing.
@mlazebny
@mlazebny 2 жыл бұрын
@@michasengotta2295 That's where get_it is not helpful. Why don't you just use global variables instead? You need to use Constructor Injection in your services, logic layers, etc.
@allenrichardyeager8449
@allenrichardyeager8449 2 жыл бұрын
same here
@ivanyoed
@ivanyoed 2 жыл бұрын
People, people. Guys. Remember that global variables can be altered by any part of the code, making it difficult to remember or reason about every possible use. ... Using global variables causes very tight coupling of code. Using global variables causes namespace pollution. The problem with global variables is that since every function has access to these, it becomes increasingly hard to figure out which functions actually read and write these variables. Just had to google a little to find so many reasons to prefer other ways to manage data in your app.
@michasengotta2295
@michasengotta2295 2 жыл бұрын
@@mlazebny Global variables are an anti-pattern for the reasons Iván provided. But even global constants are a mediocre option, because you don't want all of your code to depend on the place where you keep the variables. Inversion of dependency is the way to go here. You don't fetch the variable, but it gets delivered to you :) You bet the Google team knows this, which is why this is their package of the week!
@ivanyoed
@ivanyoed 2 жыл бұрын
Sweet. Please keep doing such amazing videos about packages which help us to code while following appropriate patterns.
@amirgamil
@amirgamil 2 жыл бұрын
Nice!!! More like this please! Understanding Flutter best practice in this way is great and I've always wanted to know what Flutter's DI options were 👍 Would love to hear more about this and other topics in this vein.
@강수경-j1b
@강수경-j1b 2 жыл бұрын
Thank you for korean subtitle :D
@mrCetus
@mrCetus 2 жыл бұрын
I really didn’t understand the use of this one, since I’m using contractors for what object I need and static variables for the app need to use during the session, so does this one provide a way that I can get the objects or what construct I have for later use in the app, like static variables!?
@JenuelDevTutors
@JenuelDevTutors 2 жыл бұрын
is their a video about best way to structure folders in a project? like creating service folders, jobs, etc. ?
@WahyuHidayat-my1ky
@WahyuHidayat-my1ky 2 жыл бұрын
better watch clean architecture course by reso coder
@Lensbreak
@Lensbreak 2 жыл бұрын
Just use Riverpod?
@Raimkhodzhanov
@Raimkhodzhanov 2 жыл бұрын
I love Flutter!
@AJFlutterTutorials
@AJFlutterTutorials 2 жыл бұрын
awesome)
@tech4nobs205
@tech4nobs205 2 жыл бұрын
Awesome 😎
@israelhudson
@israelhudson 2 жыл бұрын
If it's possible not to use context safely then is package "get" also recommended?
@codeage1
@codeage1 2 жыл бұрын
What ist the difference to the Singleton Pattern?
@alexanderphatom5410
@alexanderphatom5410 2 жыл бұрын
nothing
@ulbsualbrykya7141
@ulbsualbrykya7141 2 жыл бұрын
Using get_it as dependency injector/service locator makes life much easier to create "fake" instances and mock testing
@saqqara6361
@saqqara6361 2 жыл бұрын
Singleton Pattern is not dependency injection, which is done by get_it.
@michasengotta2295
@michasengotta2295 2 жыл бұрын
The things you provide to get_it are actually singletons. It's just the fact that you 1. have a unified way of accessing all your singletons and 2.: you can change them out at runtime, which you couldn't if you depended on concrete classes. You can however write something similar to this with little code, so it's up to you.
@ShawnBlais
@ShawnBlais 2 жыл бұрын
Think of them as testable singletons.
@scottcollins4456
@scottcollins4456 2 жыл бұрын
Are there any packages for flutter that provide constructor injection? I have always tried to stay away from service locators as much as possible, so this package isn't exactly what I was looking for in a DI framework.
@ShawnBlais
@ShawnBlais 2 жыл бұрын
Not that I know of. All options in Flutter are service locators of one type or another. Provider, riverpod, inherited widget, etc
@mrverdant13
@mrverdant13 2 жыл бұрын
what about riverpod
@pradeepg4498
@pradeepg4498 10 ай бұрын
Getx
@trapeye3464
@trapeye3464 2 жыл бұрын
what different from provider?
2 жыл бұрын
this video deserves a better version hehe
@krtirtho
@krtirtho 2 жыл бұрын
I don't get_it What's it's purpose?
@md.safiqulislam2944
@md.safiqulislam2944 2 жыл бұрын
Every widget video talk description. We want that describe give comment section.
@TheGamingAlong
@TheGamingAlong 2 жыл бұрын
I don't get_it .
@DaewonTech
@DaewonTech 2 жыл бұрын
nice one
@melianiabdelghani371
@melianiabdelghani371 2 жыл бұрын
Can i ask about the difference between this and the other methods of state management ?
@mmazurovsky_r
@mmazurovsky_r 2 жыл бұрын
It is about dependency injection, not state management
@RamVerm
@RamVerm 2 жыл бұрын
get_it is not a state management system or solution. It is used for dependency Injection. Dependency injection is used for storing, locating instances of classes and injecting it directly into widgets or methods which results in a much more cleaner and readable code rather than passing down the instance in a widget tree. It is especially useful in a complex app but normally you won't need it.
@jimmorrison2657
@jimmorrison2657 2 жыл бұрын
@@RamVerm What is the difference with this, and holding all instances in a singleton, and getting them from there?
@danijeltolj7052
@danijeltolj7052 2 жыл бұрын
@@jimmorrison2657 Using get_it in combination with abstract classes makes the code much cleaner and decoupled. Holding all instances in a singleton makes it so much harder to test and dangerously expensive in terms of memory management. Lastly, it makes testing the app a breeze, because everything is decoupled.
@jimmorrison2657
@jimmorrison2657 2 жыл бұрын
@@danijeltolj7052 The decoupling could also be done with a singleton. The singleton would only return interfaces, and you wouldn't need to know which concrete implementation you are getting. For testing, you could pass test implementations into the singleton on app start-up, then these would be returned by the getters. About memory management, I think you are wrong about this. I don't see any reason why a singleton would require more memory.
@Brayanpr27
@Brayanpr27 2 жыл бұрын
Saludos desde Colombia fluttermens
@j.almadhaji
@j.almadhaji 2 жыл бұрын
we need a full example of it I am using it with provider, but I wonder if I am using it the right way
@mmazurovsky_r
@mmazurovsky_r 2 жыл бұрын
Get it is great!
@NahomyUchija
@NahomyUchija 2 жыл бұрын
When HiveDB ?
@alexanderphatom5410
@alexanderphatom5410 2 жыл бұрын
After that there will be no point in watching this channel at all
@mr_ks_gaming
@mr_ks_gaming 2 жыл бұрын
@@alexanderphatom5410 why tho ?
@SunFoxx_
@SunFoxx_ 2 жыл бұрын
Clearly many people in the comments did not get_it *badum tss*
@michelfeinstein
@michelfeinstein 2 жыл бұрын
Unfortunately service locators can't be statically verified, so you will get runtime erros if you fail to define a dependency. This is a frequent source of bugs. I wish dart/flutter had a good DI injection mechanism, like other technologies have.
@levilesches7783
@levilesches7783 2 жыл бұрын
Personally, I define a static field on my service called "instance" with the singleton object. It's safe, since if you don't define it you can't reference it, cleaner by making DI redundant, and aligns closer to more prominent SDKs, like Firebase
@michelfeinstein
@michelfeinstein 2 жыл бұрын
@@levilesches7783 not all dependencies are singletons, so we still need mechanisms to create instances on the fly.
@neociber24
@neociber24 2 жыл бұрын
Others technologies use reflection and I think Flutter doesn't allow it.
@michelfeinstein
@michelfeinstein 2 жыл бұрын
@@neociber24 The same can be done with code generation, that what's Dagger does on Android.
@ShawnBlais
@ShawnBlais 2 жыл бұрын
@@levilesches7783 Yes, singletons are more robust, but they are harder to test/mock (well impossible really). GetIt adds a little sugar on top, to solve this limitation. imo the RTE's are not really a problem with singletons in practice, they don't typically just disappear, and you shouldn't have tons of them anyways. Singletons should be major actors in your app. The error issue is when using service locators for general instance injection, where you might insert non-singleton like objects all over your app. Then all of a sudden you can get into a case of lots of runtime errors "Cant find thing X". I stay away from that practice personally, as it seems like an obvious anti-pattern. My Flutter projects generate far too many widgets, to be injecting state at different levels of the tree and then trying to find it later.
2 жыл бұрын
I didn't get_it 😅
@DL-gg3sb
@DL-gg3sb 2 жыл бұрын
Pk. Google map can not setstate pin on web. need fix
@ahmedtiger3809
@ahmedtiger3809 2 жыл бұрын
i don't get it this one :)
@kamil_supabase_enjoyer
@kamil_supabase_enjoyer 2 жыл бұрын
Just use Riverpod instead
@mlazebny
@mlazebny 2 жыл бұрын
Nah. Get it, really? I see that the next video will be about GetX, yep?
@michaelkadziela7460
@michaelkadziela7460 2 жыл бұрын
Those two packages aren't related
@ivanyoed
@ivanyoed 2 жыл бұрын
@@michaelkadziela7460 yeah, not at all.
@nested9301
@nested9301 11 күн бұрын
Gooobrr
@danielsanchezsa6428
@danielsanchezsa6428 2 жыл бұрын
So... its like Provider?
@ShawnBlais
@ShawnBlais 2 жыл бұрын
When combined with `GetItMixin` it acts almost identical to provider, except you don't ever need to use `context` to look things up :)
@Lensbreak
@Lensbreak 2 жыл бұрын
@@ShawnBlais Riverpod does that too?
@ShawnBlais
@ShawnBlais 2 жыл бұрын
@@Lensbreak Yes, but substitutes a `ref` object instead, which must be similarly passed around.
@livingstongraphics
@livingstongraphics 2 жыл бұрын
cool
@serkankaya9907
@serkankaya9907 2 жыл бұрын
Yeah :)
@321Tdog
@321Tdog 2 жыл бұрын
Siick
@أبوتميم-ح6ط
@أبوتميم-ح6ط 2 жыл бұрын
Thank you flutter from my heart, but if you translate the clips into Arabic, thank you again 💐
@TrongTran-zv6ci
@TrongTran-zv6ci 2 жыл бұрын
Wow, now I get_it :)
@joranmulderij
@joranmulderij 2 жыл бұрын
I get it.
@virgiliustancu9293
@virgiliustancu9293 2 жыл бұрын
After "null safety" Flutter became very confusing.
@gilangs8484
@gilangs8484 2 жыл бұрын
For me, null safety is very helpful
@BrazilMentionedHueHue
@BrazilMentionedHueHue 2 жыл бұрын
hmmmm I get it
@AJHopeTV
@AJHopeTV 2 жыл бұрын
5th)
@ROWROLLIN
@ROWROLLIN 2 жыл бұрын
7번째
@dskygn
@dskygn 11 ай бұрын
Not clean, does not understand anything. State management packages sucks in flutter, very disappointed.
@ankitmahadik4081
@ankitmahadik4081 2 жыл бұрын
Second ;)
@ShanXiTV
@ShanXiTV 2 жыл бұрын
if you are accessing repo or db from UI, u r doing it wrong. Move that logic to bloc.
@BenMcNelly
@BenMcNelly 2 жыл бұрын
Third?
@ahsan_khan44
@ahsan_khan44 2 жыл бұрын
4th :p
@baxiry.
@baxiry. 2 жыл бұрын
6th
@srujanmhase2832
@srujanmhase2832 2 жыл бұрын
First ;)
@vanhelsing4454
@vanhelsing4454 2 жыл бұрын
I thought its a video about GetX
@mazudhafiz1778
@mazudhafiz1778 2 жыл бұрын
Different :D
@ElVerdaderoAbejorro
@ElVerdaderoAbejorro 10 ай бұрын
It's a shame that in 2023 people use the terms "Service locator" and "Dependency Injection" as if they mean the same thing. Service Locator is an anti-pattern. Read "Dependency Injection: Principles, Patterns and Practice" if you don't know the difference. Shame on this video for pushing towards a SL library instead of true DI.
@csibesz07
@csibesz07 9 ай бұрын
service locators = DI frameworks - explicit dependency declarations
@nimrsawafta1682
@nimrsawafta1682 2 жыл бұрын
I really didn’t understand the use of this one, since I’m using contractors for what object I need and static variables for the app need to use during the session, so does this one provide a way that I can get the objects or what construct I have for later use in the app, like static variables!?
@ShawnBlais
@ShawnBlais 2 жыл бұрын
It's essentially a singleton manager, globally accessible objects, accessed by type from anywhere in the app, easily mocked/replaced.
@javieroviedo4844
@javieroviedo4844 2 жыл бұрын
Static variables that hold states are an antipattern because they difficult unit testing and a couple of other reasons. This is suppose to be a service locator that easily lets you control the lifetime of the service and decouple its dependencies, it appears to be heavely inspired by the dependency injection of the .net ecosystem, is convenient because it facilitates mocking that dependency too.
@xylineone
@xylineone 2 жыл бұрын
This is something like spring for dependency injection
@j.almadhaji
@j.almadhaji 2 жыл бұрын
define it out side the class or any function, then assign to it what you want later before the RunApp(), you will be able to access it from any where. final getIt = GetIt.instance;
@ahmedhesham3916
@ahmedhesham3916 2 жыл бұрын
I didn't get_it 😅
@alexcom_
@alexcom_ 6 ай бұрын
I don't get_it.
path_provider (Package of the Week)
1:44
Flutter
Рет қаралды 90 М.
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 34 МЛН
小蚂蚁会选到什么呢!#火影忍者 #佐助 #家庭
00:47
火影忍者一家
Рет қаралды 58 МЛН
Крутой фокус + секрет! #shorts
00:10
Роман Magic
Рет қаралды 35 МЛН
Freezed (Package of the Week)
2:57
Flutter
Рет қаралды 185 М.
Dependency Injection in Flutter - You HAVE to Use it !
7:07
Flutter Guys
Рет қаралды 18 М.
Theme (Flutter Hallowidget of the Week)
3:23
Flutter
Рет қаралды 167 М.
13 Things To Remove From Your Website Immediately
12:33
Orbit Media Studios
Рет қаралды 322 М.
Collection (Flutter Package of the Week)
2:16
Flutter
Рет қаралды 105 М.
Top 30 Flutter Tips and Tricks
6:50
Flutter Mapp
Рет қаралды 561 М.
how I would learn digital marketing (If I could start over)
19:52
Senator We Run Ads
Рет қаралды 1,8 МЛН
mason (Package of the Week)
2:36
Flutter
Рет қаралды 153 М.
Why Agent Frameworks Will Fail (and what to use instead)
19:21
Dave Ebbelaar
Рет қаралды 70 М.
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 34 МЛН