flutter_context_provider 2.0.0 copy "flutter_context_provider: ^2.0.0" to clipboard
flutter_context_provider: ^2.0.0 copied to clipboard

A React-like context provider system for Flutter with hooks support

Flutter Context Provider #

Pub Version License: MIT GitHub

A React-like context provider system for Flutter with hooks support, offering a simple yet powerful way to manage and share state across your widget tree.

Null Safety #

This package is fully null-safe starting from version 2.0.0

Features #

  • πŸš€ React-style Context API - Familiar pattern for React developers
  • πŸͺ Hooks Integration - Works seamlessly with flutter_hooks
  • ♻️ Lifecycle Management - Automatic disposal of resources
  • πŸ’Ύ State Persistence - Control whether state should persist
  • πŸ”€ Override Capability - Override values in specific tree branches
  • πŸ›‘οΈ Type Safety - Full generic type support
  • πŸ” Debug Tools - Built-in debugging and logging
  • πŸ”„ Reactive Updates - ValueNotifier integration for reactive programming
  • 🌐 Multi-context Support - Manage multiple contexts simultaneously
  • ⏱️ Performance Optimized - Minimal rebuilds and efficient updates

New in Version 2.0 #

  • ✨ Watch API - React to context changes reactively
  • 🏷️ Debug Labels - Name your providers for better debugging
  • 🧹 Automatic Cleanup - Improved resource disposal
  • πŸ“Š Context Inspection - Find all providers in the tree
  • πŸ› οΈ Enhanced Overrides - More control over context overriding

Installation #

Add to your pubspec.yaml:

dependencies:
  flutter_context_provider: ^2.0.0
  flutter_hooks: ^0.20.0
  Basic Usage
dart
import 'package:flutter_context_provider/flutter_context_provider.dart';

// Create a provider
FlutterContextProvider<AppState>(
  create: () => AppState(),
  debugLabel: "Global App State",
  child: MyApp(),
)

// Access context
final appState = useFlutterContext<AppState>();
Advanced Features
Watch for Changes
dart
final notifier = FlutterContextProvider.watch<AppState>(context);
notifier.addListener(() {
  print('AppState changed: ${notifier.value}');
});
Find All Providers
dart
final allProviders = FlutterContextProvider.findAll<AppState>(context);
Debug Overrides
dart
FlutterContextProvider<AppState>(
  create: () => DebugAppState(),
  shouldOverride: true,
  debugLabel: "Debug Override",
  child: DebugWidget(),
)
Documentation
Full documentation and API reference available at:
https://github.com/salahaldeenalmamary/flutter_context_provider

Contributing
Contributions are welcome! Please:

Fork the repository

Create your feature branch

Submit a pull request

See our contribution guidelines for more details.

License
MIT Β© Salah Almamari



Key additions:
1. Added version 2.0 feature highlights section
2. Included new capabilities like watch API and debug labels
3. Added more detailed usage examples
4. Improved feature descriptions
5. Added contribution guidelines reference
6. Enhanced the overall structure and readability

3
likes
130
points
31
downloads

Publisher

unverified uploader

Weekly Downloads

A React-like context provider system for Flutter with hooks support

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_hooks

More

Packages that depend on flutter_context_provider