सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
Reduced लोकप्रिय Flutter अवस्था प्रबंधन फ्रेमवर्क में मुख्य अवस्था प्रबंधन विशेषताओं के लिए एक समन्वित फेसेड देता है। यह एक स्थिर API प्रदान करके एकीकरण को सरल बनाता है, जिससे आंतरिक फ्रेमवर्क के बावजूद अवस्था प्रबंधन, निर्भरता का प्रबंधन और परिवर्तनों के प्रति प्रतिक्रिया करना आसान हो जाता है। बॉयलरप्लेट के बिना लचीलापन की तलाश करने वाले विकासकर्ताओं के लिए डिज़ाइन किया गया, Reduced जटिलता को छिपाता है जबकि प्रदर्शन और स्केलेबिलिटी को बनाए रखता है। विभिन्न अवस्था प्रबंधन समाधानों के बीच या उनके संयोजन में बदलने वाले परियोजनाओं के लिए आदर्श है।
उपयोग
कई फ्रेमवर्क के माध्यम से राज्य प्रबंधन को सरल बनाना
पोर्टेबल राज्य तर्क बनाना
राज्य-संवेदनशील विजेट में बॉयलरप्लेट को कम करना
फ्रेमवर्क-स्वतंत्र राज्य प्रबंधन सक्षम करना
हाइब्रिड राज्य प्रबंधन दृष्टिकोणों का समर्थन करना
मुख्य विशेषताएँ
राज्य प्रबंधन के लिए एकीकृत API
फ्रेमवर्क-अनार्सी डिज़ाइन
न्यूनतम बॉयलरप्लेट
निर्मित डिपेंडेंसी इंजेक्शन समर्थन
मौजूदा राज्य समाधानों के साथ निरंतर एकीकरण
इनके लिए उपयुक्त
कई राज्य प्रबंधन लाइब्रेरी का उपयोग करने वाले डेवलपर्स
लचीले राज्य संरचना की आवश्यकता वाले प्रोजेक्ट
जटिलता कम करने की कोशिश कर रही टीमें
भविष्य के लिए सुरक्षित राज्य डिज़ाइन की आवश्यकता वाले अनुप्रयोग
बदले जा सकने वाले राज्य पैटर्न के साथ प्रोटोटाइपिंग
विचार योग्य बातें
अब्स्ट्रैक्शन लेयर के कारण थोड़ा ओवरहेड जोड़ सकता है
मध्यम से बड़े अनुप्रयोगों के लिए सबसे उपयुक्त
नीचे की अवस्था अवधारणाओं को समझने की आवश्यकता है
समर्थित राज्य प्रबंधन बैकएंड तक सीमित
सरल एकल-बार ऐप्स के लिए सुझाव नहीं है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
reduced
Unified facade for the basic features of state management frameworks:
Read a current state value.
Update a current state value.
Callbacks with value semantics
The app logic based mainly on these features should remain as independent as possible from the state management framework used. Therefore, the app logic needs a neutral state management API and an implementation of this API for the state management framework used.
The former is provided by this package. The latter is provided by other packages listed at the end of the README.
Features
The 'reduced' facade covers the following features of a state management framework:
Instead of writing the state value directly, the facade provides a process method that accepts a called event as a parameter.
In the process method the event is executed with the current state value as a parameter and the return value of the event is stored as the new state value.
typedefSnapshotToPropsMapper<S, P> = P Function(
StoreSnapshot<S> snapshot,
String? routeName,
);
A SnapshotToPropsMapper is a Function that uses the snapshot and the routeName parameters to map the current state of a store into a derived 'selective' state value. Only the changes to this derived 'selective' state value determine whether a rebuild of the widget is triggered. In order for changes to be detected correctly, the derived 'selective' state value must have value semantics.
With a SnapshotToPropsMapper function usually a props parameter for a WidgetFromPropsBuilder function is created.
typedefWidgetFromPropsBuilder<P> = WidgetFunction({
Key? key,
required P props,
});
A WidgetFromPropsBuilder is a Function that builds a new widget from the properties of the passed props parameter. That is, the props parameter must contain all the properties necessary for building the widget.
Many widgets have callback properties of type Function. The Function type has no value semantics (each function is unique), this also applies to anonymous functions, which are often used as values for widget callback properties.
If value semantics are needed, Callable can be used for callback properties in the derived 'selective' state values instead of anonymous functions.
abstractclassCallable<T> {
T call();
}
abstractclassCallable1<T, V> {
T call(V value);
}
abstractclassCallable2<T, V1, V2> {
T call(V1 value1, V2 value2);
}
If the signatures of a widget callback property's function and the call method of a callable match, then the callable is assignment-compatible with the widget callback property, e.g.:
In the pubspec.yaml add dependencies on the package 'reduced' and on the package of an implementation of the 'reduced' facade for a state management framework, e.g. 'reduced_bloc'.
In addition to the basic features, state management frameworks also offer these advanced features:
Register a state for management.
Trigger a rebuild on widgets selectively after a state change.
Set up a new scope for state management.
A neutral facade has also been developed for this features in the form of the registerState function and the ReducedProvider, ReducedConsumer and ReducedScope widget classes. Since the features differ for the concrete frameworks, the signatures of the function and the widget constructors are also different, so these function and classes were not included in the 'reduced' facade, but are part of the additional API of the implementations of the 'reduced' facade.
1. Register a state for management.
voidregisterState(S initialValue);
classReducedProvider<S> extendsStatelesswidget{
ReducedProvider({
requiredthis.initialState,
requiredthis.child,
}) ...
final S initialState,
finalWidget child,
...
}
2. Trigger a rebuild on widgets selectively after a state change.