feat(controllers): enhance documentation, add lifecycle callbacks, an…#3361
feat(controllers): enhance documentation, add lifecycle callbacks, an…#3361jonataslaw merged 2 commits intojonataslaw:masterfrom Aniketkhote:master
Conversation
Aniketkhote
commented
Jun 6, 2025
- Improve documentation for all controller classes with usage examples
- Add error handling in FullLifeCycleMixin callbacks
- Implement onMemoryPressure and onAccessibilityChanged callbacks
- Add proper ScrollController disposal in ScrollMixin
- Enhance type safety and error reporting
- Update documentation with clear method descriptions and examples
- Fix potential memory leaks in lifecycle management
…d improve error handling
jonataslaw
left a comment
There was a problem hiding this comment.
Thank you very much for this PR. The documentation is generally well written, but I have some concerns regarding the try/catch blocks.
The first one is meant to handle a case where update() is called before the controller has been initialized. However, this is impossible, since the constructor itself initializes the controller. In other words, by the time we call controller.update(), the controller is already initialized. This makes the try/catch both unnecessary and a source of extra overhead.
Second, the lifecycle methods are meant to be overridden by the user. If they override without calling super, the try/catch will never execute; if they override and call super, they’ll simply run an empty block (or Flutter’s default code). In my opinion, this try/catch is also unnecessary and can actually confuse debugging: if an error is thrown, the stack trace will point to the library code rather than the function that actually caused the error.
| } else { | ||
| for (final id in ids) { | ||
| refreshGroup(id); | ||
| try { |
There was a problem hiding this comment.
Interesting, could you explain in which situation the update block could face an exception to make this try/catch necessary?
|
I've addressed the feedback with the following changes: Removed try-catch blocks from lifecycle methods to align with Flutter's idiomatic error handling, allowing better debugging and letting global handlers catch issues. Simplified the update() method by removing redundant error handling—it's safe as the controller is already initialized. Kept documentation improvements for better developer clarity. These changes follow Flutter best practices, giving developers more control while improving maintainability. |
|
Thank you! |
|
any new updates?? |