Whats new in BLOC 8?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome back to flutter from scratch in today's video we'll be having a bit of a look at some of the upcoming changes to the flutter block state management solution [Music] [Applause] [Music] [Applause] [Music] there's probably a pretty good chance that you're using the state management solution in your flutter apps considering how popular it is on pub dev now as we mentioned there are some changes coming up this package now as developers and as cross-platform developers we tend to really not like changes and we tend to particularly dislike breaking changes when we have to make a change to our code to facilitate a new update to a package we're using and you know that makes sense it's annoying to have to change something that maybe for you was working fine just because something has changed in a package that you use well that's pretty much what's happening with flutter block in its next release the map event to state method will be going away in favor of event handlers now obviously map event to state is central to how flutterblock works and how it runs at state management events come in and then states are yielded back out through that map event to state function if map event to state is going away that's a pretty big change to how flutterblock works it also means you can't upgrade to the newest version of flood and block without first making some changes in how your blocks work in your apps now you might be there and you might be like why why is it like this there wasn't anything wrong with how it used to work and to be fair when i read the deprecation warning in android studio that this was coming i felt a similar way i hadn't noticed any issues in my apps so why was flutterblock changing well as it turns out there's actually three good reasons why these changes are taking place first there's actually a bug in how dart handles streams that yield over time there's a really long github issue that goes into great depth about what these issues are and it has some pretty good commentary from felix the guy who created flutterblock talking about some issues that he observed in how dart processes streams sometimes streams can yield in a way that you're not expecting them to and it seems to be related to a very small timing issue now obviously block user streams heavily both to accept events into blocks and also to yield new states so if block is built on top of streams and the streams are working inconsistently then we can't be sure that our blocks are going to work consistently either right if our streams can't be consistent and reliable it means that the states coming out of our block can't be consistent or reliable but fortunately with upcoming changes to flutter block we actually work with reality's issues secondly the way the block works today is pretty good obviously we have the map event estate to map events in two states but it does contribute to a little bit of boilerplate now obviously in order to have a block we have our map event to state function within our block and then we have our events come in and then we yield states appropriately we're supposed to break out our functionality in here into smaller bits and pieces to make it more readable and more maintainable but if you're anything like me your map event estate method just grows and grows and grows as you add functionality over time because the new way that photoblock works relies on event handlers and not map event estate we actually save on a lot of boilerplate instead we just use the on function to register event handlers and then we omit the new state as we would expect to this actually reduces the amount of code that we need to write which can increase readability and make it easier for us to work on our apps which is always a good thing third and finally it makes it easier to work with asynchronous streams within our apps normally with our app if we'd like to subscribe to a stream and then yield asynchronously from it into our block and then up into our app you have to use a yield generator function to subscribe to these changes over time and then to yield them into your block state but if the stream that you're subscribed to never comes to an end or encounters some other kind of issue it can be easy to have your block get stuck in a state where it just never finishes because the stream is depending on never finishes either but people who are new to flutter and working with streams might struggle with that particular aspect occasionally a stream that you subscribe to may just never complete which causes your map event to state method to never complete either fortunately with the upcoming changes to flutter block we don't actually have to use these yield generators anymore instead of that we can just emit a new state whenever we want to that means it's easier and more consistent to subscribe to a stream of data well that's the upcoming changes to flutter block in a nutshell if you'd like you can read the migration guide that's attached to this video or you can come and ask questions in a flutter block discord channel if you're just getting started with flutter and flutter block now's a great time to be doing so as your new code will obviously adhere to this standard and you'll benefit from all these improvements but if you're more like me and you have quite a few old apps that you'll have to migrate manually to make this work then happy migrations to you may your code compile the first time and your tests pass on the first attempt until next time this has been flutter from scratch
Info
Channel: Flutter From Scratch
Views: 538
Rating: undefined out of 5
Keywords:
Id: iXS17TFwEu8
Channel Id: undefined
Length: 5min 38sec (338 seconds)
Published: Mon Nov 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.