data_handler 0.0.4 copy "data_handler: ^0.0.4" to clipboard
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 of List<Widget>
    • Removed automatic Column wrapping
    • Added whenSliverList() for Sliver widgets

Removed Parameters

  • context parameter (no longer required)
  • progressIndicatorColor
  • progressIndicator
  • errorWidget
  • emptyWidget
  • errorStyle
  • emptyStyle
  • isEnabled β†’ renamed to enabled

✨ 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 #

  1. Update when() calls:

    // Remove context parameter
    // Change builder names: loadingBuilder β†’ onLoading, etc.
    // Remove widget properties, use callbacks instead
    
  2. Update widget configuration:

    // Instead of passing widgets as parameters
    // Set them globally or use callbacks
    
  3. 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 and whenList parameters
  • New widget customization properties:
    • progressIndicatorColor - Custom loading indicator color
    • progressIndicator - Custom loading widget
    • errorWidget - Custom error display widget
    • emptyWidget - Custom empty state widget
    • errorStyle - Custom text styling for errors
    • emptyStyle - Custom text styling for empty state
    • isEnabled - Toggle to enable/disable state handling
  • Updated examples with new features
  • Added screenshots for documentation

0.0.2 #

Added #

  • Example implementation for data_handler plugin
  • Enhanced widget support for better UI handling

Fixed #

  • Resolved critical issue with data_handler plugin functionality
  • Improved stability and performance

0.0.1 #

Added #

  • Initial release of data_handler plugin
  • Basic state management for loading, success, error, and empty states
  • Core DataHandler<T> class with ChangeNotifier integration
  • Basic when() method for conditional widget rendering

Migration from 0.0.3 to 0.0.4 #

Quick Migration Steps: #

  1. Remove context parameter:

    // Before
    handler.when(context: context, ...)
    // After  
    handler.when(...)
    
  2. Update callback names:

    // Before
    loadingBuilder: (context) => Widget()
    successBuilder: (data) => Widget()
       
    // After
    onLoading: () => Widget()
    onSuccess: (data) => Widget()
    
  3. Replace widget properties with callbacks:

    // Before
    errorWidget: MyErrorWidget()
       
    // After
    onError: (error) => MyErrorWidget(error)
    
  4. 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.

2
likes
150
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

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 loading, error handling, and data retrieval, while ensuring a clean and maintainable codebase.

Repository (GitHub)
View/report issues

Topics

#data #widget #data-handler #api #state

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on data_handler