

#BLOC OBSERVER FLUTTER CODE#
Then, as mentioned above, I did spend some energy on Bloc to optimize its use, then read his source code, and then think about the Provider source code I saw before, and suddenly I felt a huge gap. It was a hearty feeling! After the pain, there is a huge sense of satisfaction, and I am amazed by the Provider's proficient use of various APIs in the Framework layer, and then the wonderful refresh mechanism! The internal logic was indeed a bit complicated, but the overall process was clear and the logic was refreshed. When I was looking at the Provider source code before, I had a headache. But: code will not lie, all the good or bad are in it, and you can feel it with your heart.I also used Bloc for a long time, in-depth use of the process, some optimizations to its usage, and also wrote a code generation plug-in for it, I also paid some time and energy for it.I have complained a lot, it’s not that I have any opinion on bloc When the emit or yield refresh is called, the map of _dependents is always empty, hey. The callback in the _startListening method called e.markNeedsNotifyDependents(), completely useless ! Provider.of(context, listen: true) not used to add a child Element to InheritedElement, it is a refreshing loneliness! In order to verify my idea, I notif圜lients method of the framework layer. The Bloc framework did some operations that made me very puzzled.Even if the bloc framework uses a line in the build widget: Provider.of(context, listen: true) or remove e.markNeedsNotifyDependents(), I won’t say that.I think the author of Bloc may be a little confused about the refresh mechanism of Provider. Star 10. Flutter Bloc Library Tutorial - Bloc Observer Debug and Observe your Bloc Easily Rabee Omran 2.66K subscribers Subscribe 577 views 2 months ago Bloc. The most classic refresh mechanism of the Provider is completely useless! However, only the child node in the Provider is used to query the data of the nearest parent node's InheritedElement and the top-level Widget parallel layout function.Here I confirm: This is true, Bloc does seal the Provider.You may be in the group and often see some older brothers saying: Bloc encapsulates the Provider. This state layer is added, I think it is quite necessary, because once a page maintains a lot of state, mixing state variables and logic methods together, the later maintenance will be very headache. The BLoC pattern focuses on separating business logic from the UI, using two main principles: Streams: Streams handle widget state changes, ensuring that any changes to widget state come through. This layer must be separated separately I feel that if it had not been pitted by the Cthulhu code mountain of large projects, it would not have been so. The state layer is written directly inside the framework. The author is still very old in the division of levels. Those who have used Bloc can definitely feel that the Bloc framework has made a clear division of the development page, and the framework has forced two development modes.īloc mode: This mode is divided into four layers of structureĬubit mode: This mode divides a three-layer structure


/ Once is called, the instance can no longer be used.Preface After reading the Bloc source code, I feel a bit complicated. / This method should be called when the instance is no longer needed.

Import 'package:flutter/material.dart' import 'package:flutter_bloc/flutter_bloc.dart' enum CounterActions /// Closes the instance.
