data_handler 0.0.4
data_handler: ^0.0.4 copied to clipboard
Refactored architecture with enhanced global configuration for state management and data handling in Flutter applications. This package provides a robust solution for managing API states, including lo [...]
0.0.4 #
π¨ BREAKING CHANGES #
This version introduces a complete architectural redesign. All existing code using v0.0.3 will need to be updated.
API Changes
-
when()
method signature completely changed:// OLD (v0.0.3) dataHandler.when( context: context, loadingBuilder: (context) => Loading(), successBuilder: (data) => Success(data), progressIndicatorColor: Colors.blue, errorWidget: ErrorWidget(), ) // NEW (v0.0.4) dataHandler.when( onLoading: () => Loading(), onSuccess: (data) => Success(data), onError: (error) => Error(error), onEmpty: (message) => Empty(message), )
-
whenList()
method redesigned:- Now returns
Widget
instead ofList<Widget>
- Removed automatic Column wrapping
- Added
whenSliverList()
for Sliver widgets
- Now returns
Removed Parameters
context
parameter (no longer required)progressIndicatorColor
progressIndicator
errorWidget
emptyWidget
errorStyle
emptyStyle
isEnabled
β renamed toenabled
β¨ New Features #
Global Widget Configuration
// Set global defaults for your entire app
DataHandlerConfig.setGlobalWidgets(
loadingWidget: () => CustomLoader(),
errorWidget: (error) => CustomError(error),
emptyWidget: (message) => CustomEmpty(message),
);
Enhanced Performance
- Smart rebuild optimization - Only rebuilds when state actually changes
- AnimatedBuilder integration for smoother transitions
- Memory optimization with automatic cleanup
New Methods
// Convenient data refresh
await dataHandler.refresh(() => apiService.getData());
// Direct data updates without loading state
dataHandler.updateData(newData);
// Reset to empty state
dataHandler.clear();
// Check if data exists and is successful
if (dataHandler.hasSuccess) { ... }
List Handling Enhancement
// Enhanced list support
DataHandler<List<User>> users = DataHandler();
// Check list properties
print(users.isListEmpty); // true if null or empty
print(users.listLength); // 0 if null, length otherwise
// Specialized list widget builder
users.whenList(
onSuccess: (list) => ListView.builder(...),
onEmptyList: (message) => EmptyListWidget(),
);
Sliver Support
// Perfect for CustomScrollView
CustomScrollView(
slivers: [
dataHandler.whenSliverList(
itemBuilder: (data, index) => ListTile(...),
itemCount: (data) => data.length,
),
],
)
π§ Migration Guide #
-
Update
when()
calls:// Remove context parameter // Change builder names: loadingBuilder β onLoading, etc. // Remove widget properties, use callbacks instead
-
Update widget configuration:
// Instead of passing widgets as parameters // Set them globally or use callbacks
-
Update
whenList()
usage:// Now returns single Widget, not List<Widget> // Remove manual Column wrapping
π Documentation #
- Added comprehensive inline documentation
- Included usage examples for all methods
- Performance optimization guidelines
0.0.3 #
Added #
- Support for
when
andwhenList
parameters - New widget customization properties:
progressIndicatorColor
- Custom loading indicator colorprogressIndicator
- Custom loading widgeterrorWidget
- Custom error display widgetemptyWidget
- Custom empty state widgeterrorStyle
- Custom text styling for errorsemptyStyle
- Custom text styling for empty stateisEnabled
- Toggle to enable/disable state handling
- Updated examples with new features
- Added screenshots for documentation
0.0.2 #
0.0.1 #
Added #
- Initial release of
data_handler
plugin - Basic state management for loading, success, error, and empty states
- Core
DataHandler<T>
class withChangeNotifier
integration - Basic
when()
method for conditional widget rendering
Migration from 0.0.3 to 0.0.4 #
Quick Migration Steps: #
-
Remove context parameter:
// Before handler.when(context: context, ...) // After handler.when(...)
-
Update callback names:
// Before loadingBuilder: (context) => Widget() successBuilder: (data) => Widget() // After onLoading: () => Widget() onSuccess: (data) => Widget()
-
Replace widget properties with callbacks:
// Before errorWidget: MyErrorWidget() // After onError: (error) => MyErrorWidget(error)
-
Consider using global configuration:
// Set once in main.dart DataHandlerConfig.setGlobalLoadingWidget(() => MyLoader());
Need Help? #
Check the updated documentation and examples in the repository for detailed migration guidance.