7/1/2023 0 Comments Bloc observer flutterThe app is borderline ugly, but it’ll help us understand this new way of doing things. Along the way, we’ll also see how the new BLoC pattern makes our lives easier. Now, let’s create a rudimentary app that uses the old BLoC pattern and convert it to make it work with flutter_bloc 8.0.0. Converting the old BLoC pattern to work with flutter_bloc 8 Not pictured here is the improvement that we’ll have by using streams. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag. Advisory boards aren’t just for executives.Explore Tauri, a new framework for building binaries.Discover how to animate your React app with AnimXYZ.Switch between multiple versions of Node.Use React's useEffect to optimize your application's performance.Learn how LogRocket's Galileo cuts through the noise to proactively resolve issues in your app.Don't miss a moment with The Replay, a curated newsletter from LogRocket.That’s almost a reduction by half, which improves code readability. Instead of taking up 17 lines to do this, we only take 10. We respond to these events not by yielding a new state, but by instead calling emit with our new state.Īnd secondly, it’s a lot shorter. Instead, our events register as event handlers. The way this worked in flutter_bloc 7 was like the following: enum CounterEvent įirst, mapEventToState is gone. The way that flutter_bloc implements the BLoC method of state management is very simple: events come in and states come out, meaning we send events into our BLoC and yield any range of states (like loaded, success, or failure). Let’s dive into what these changes look like and how they’ll affect you. These changes make it easier to work with streams and enable apps to work in a more consistent and reliable manner. For a brief summary of the changes, and why they are an improvement to what we have today, check out my video. However, I can safely say that the changes with flutter_bloc are worthwhile and drastically improve the functionality and stability of what was already a great offering. And sometimes I’ve had to migrate between a version for a breaking change and it didn’t feel worthwhile. Surely, it’d be better if the maintainers of flutter_bloc just left things alone and only implemented improvements that meant we didn’t need to do anything, right? It’s code maintenance in its ugliest format: fixing problems we feel we didn’t create. It’s hard to update a package and find it has a slew of migration requirements, and worse, that you must perform these migrations by hand, meaning you can’t use any tools to automatically do it for you. This trend has continued, and with the latest release of flutter_bloc, there are some breaking changes that require users to upgrade some of the code within existing Flutter apps by hand. Occasionally, as Flutter improves over time, the flutter_bloc library evolves alongside it. One area of Flutter that these packages support is state management, and BLoC is one of the oldest forms of state management within Flutter, originally released to the public towards the end of 2019. Introduction to Flutter BLoC 8įlutter is a comparatively new cross-platform software development framework with an incredible amount of high-quality, well-supported open sourced packages released during its short lifespan. Given the chance, I'll talk to you for far too long about why I love Flutter so much. Lewis Cianci Follow I'm a passionate mobile-first developer, and I've been making apps with Flutter since it first released.
0 Comments
Leave a Reply. |