आप आपूर्ति के साथ Redux का उपयोग करने की अनुमति देता है। AsyncRedux, Redux का बिना बॉइलरप्लेट वर्जन (https://pub.dev/packages/async_redux) का उपयोग करता है।
सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
provider_for_redux के उपयोग से AsyncRedux के माध्यम से Provider और Redux के बीच निरंतर एकीकरण होता है, जो एक हल्के, बॉइलरप्लेट-मुक्त Redux वास्तुकला है। यह डेवलपर्स को डिपेंडेंसी इंजेक्शन के लिए Provider की सरलता का उपयोग करने की अनुमति देता है, जबकि Redux के पूर्वानुमानित रूप से राज्य प्रबंधन का लाभ उठाता है। यह पैकेज संरचित राज्य नियंत्रण की आवश्यकता वाले ऐप्स के लिए आदर्श है जिसमें अत्यधिक कोड नहीं होता है। यह सभी प्रमुख प्लेटफॉर्मों का समर्थन करता है और असिंक्रोनस एक्शन और अपरिवर्तनीय राज्य पैटर्न के माध्यम से राज्य अपडेट को सरल बनाता है।
उपयोग
स्केलेबल स्टेट मैनेजमेंट के लिए प्रदाता को रेडक्स के साथ जोड़ना
पूर्वानुमानित राज्य प्रवाह के साथ बड़े पैमाने पर Flutter ऐप बनाना
जटिल एप्लिकेशन में स्थिति तर्क को सरल बनाना
Provider के प्रतिक्रियाशील विजेट्स के साथ AsyncRedux का उपयोग करना
मौजूदा Redux तरीके को एक स्पष्ट पैटर्न में स्थानांतरित करना
मुख्य विशेषताएँ
Provider को AsyncRedux के साथ एकीकृत करें
पारंपरिक रेडक्स की तुलना में बॉयलरप्लेट कम करता है
असिंक्रोनस अवस्था अपडेट का समर्थन करता है
प्रकार सुरक्षित अवस्था और कार्रवाई प्रबंधन प्रदान करता है
सभी फ्लटर प्लेटफॉर्म पर काम करता है
इनके लिए उपयुक्त
Redux के परिचित विकासकर्ता
संरचित अवस्था प्रबंधन की आवश्यकता वाली टीमें
प्रतियोगिता और राज्य नियंत्रण दोनों की आवश्यकता वाले प्रोजेक्ट
जटिल राज्य तर्क वाले ऐप्स
रेडक्स बॉलरप्लेट को बचाना चाहने वाले
विचार योग्य बातें
प्रोवाइडर और रेड्यूक्स के विचारों को समझने की आवश्यकता होती है
छोटे ऐप्स के लिए जटिलता जोड़ सकता है
AsyncRedux पर निर्भर है, जिसका अपना सीखने का वक्र है
सरल राज्य की आवश्यकता के लिए सुझाव नहीं है
मध्यम से बड़े प्रोजेक्ट्स के लिए सबसे उपयुक्त
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
provider_for_redux
With Provider you can inject your state, but it's
your job to figure out how to update that state, structure the solution etc. In other words,
Provider is a great alternative to InheritedWidget, and lets you do dependency injection, but you
still need to do your own state management.
What people mean by “Provider as state management” is usually using Provider to do scoped model. But
as a matter of fact, this is not the only possible architecture using Provider. You can use it with
Bloc, Mobx, Redux and other.
This package lets you use it with AsyncRedux, the
non-boilerplate version of Redux.
How to use it
Please, read the async_redux documentation first,
if you haven't already.
You should have learned that to use AsyncRedux the traditional way, you provide the Redux store to
your app by wrapping it with a StoreProvider, and then using the so called "connector" widgets,
like the MyHomePageConnector below:
Now, if you want to use AsyncRedux with Provider, simply remove the StoreProvider and
use AsyncReduxProvider instead. Also, you won't need the connector widgets anymore, since you will
use Provider instead.
For example:
@overrideWidgetbuild(BuildContext context) =>
AsyncReduxProvider<AppState>.value( // Instead of StoreProvider.
value: store,
child: MaterialApp(
home: MyHomePage(), // Instead of MyHomePageConnector.
));
The AsyncReduxProvider widget above will expose the store, the state, and the dispatch method to
its descendants:
The Redux store, of type Store. Get it like this: Provider.of<Store<AppState>>(context).
The store's state, of type AppState. Get it like this: Provider.of<AppState>(context).
The dispatch method, of type Dispatch. Get it like this: Provider.of<Dispatch>(context).
Your selector parameter must return a "model"
which you can use to build your widget in the builder parameter. In the above example the model is
a Tuple2 instance, but you can return any immutable object that correctly implements equals and
hashcode. The widget will rebuild whenever the model changes.
But it's easier if you use ReduxSelector, which already gives you the store, the state, and the
dispatch method:
However, ReduxSelector also lets you return a List as the model. In case you do that, it will
rebuild the widget whenever any of the items in the list changes:
Using ReduxSelector with a list is the easiest way of all, since you just need to list all of
the state parts that should trigger a rebuild.
Note: The builder gives you both the state and the model, and you can choose one of them
to build your widget from. While using state is probably easier for you, it's also easier to
accidentally use something you forget to add to the model, and then wonder why the Widget doesn't
rebuild. So you have two options:
Use only the model and have the compiler make sure there's no state you're using from outside
of the model.
Use state directly, and have yourself the responsibility to make you've listed everything you'
re using in the model.
When you use AsyncReduxProvider you will notice that both Provider and
AsyncRedux's StoreConnector
will work simultaneously. You can mix and match both of them, as desired, or slowly migrate between
them.