सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
Redux एक पूर्वानुमानित अवस्था प्रबंधन समाधान है जो Dart और Flutter एप्लिकेशन के लिए है, जो JavaScript में Redux पर आधारित है। यह एक केंद्रीकृत स्टोर प्रदान करता है जो ऐप अवस्था को प्रबंधित करता है, शुद्ध रिड्यूसर कार्यों के माध्यम से स्थिर अपडेट सुनिश्चित करता है। मिडलवेयर समर्थन और डेव टूल्स एकीकरण के साथ, यह डीबगिंग और समय-यात्रा क्षमता की अनुमति देता है। विस्तार के लिए डिज़ाइन किया गया है, यह बड़े या मध्यम आकार के ऐप्स के लिए उपयुक्त है जिनमें बहुत से कंपोनेंट्स के बीच संरचित अवस्था प्रबंधन की आवश्यकता होती है।
उपयोग
जटिल ऐप स्थिति का प्रबंधन
समय-यात्रा डिबगिंग सक्षम करें
बड़े पैमाने पर Flutter एप्लिकेशन का समर्थन करना
साइड इफेक्ट्स के लिए मिडलवेयर के साथ एकीकरण
राज्य तर्क पर टीम सहयोग को सुगम बनाना
मुख्य विशेषताएँ
केंद्रीय राज्य स्टोर
अपरिवर्तनीय राज्य अद्यतन
मध्यस्थ समर्थन
DevTools एकीकरण
पूर्वानुमानित राज्य संक्रमण
इनके लिए उपयुक्त
बड़े Flutter प्रोजेक्ट
संरचित राज्य प्रबंधन की आवश्यकता वाली टीमें
डिबगिंग फीचर्स की आवश्यकता वाले ऐप्स
Redux पैटर्न के साथ परिचित विकासकर्मी
जटिल डेटा फ्लो वाले प्रोजेक्ट्स
विचार योग्य बातें
शुरुआती लोगों के लिए सीखने का ढलान अधिक तीव्र है
आवश्यक बॉयलरप्लेट कोड
सरल ऐप्स के लिए अत्यधिक
राज्य डिज़ाइन की सावधानी से आवश्यकता होती है
सीमित निर्मित एसिंक हैंडलिंग
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Redux for Dart using generics for typed State. It includes a rich ecosystem of Docs, Middleware, Dev Tools and can be combined with Flutter using the flutter_redux package.
Docs
Motivation and Principles - Learn why Redux might make sense for your app and the principles behind it.
Basics - Introduction to the core concepts in Redux
Combining Reducers - combineReducers works a bit differently in Dart than it does in JS. Learn why, and how to combine reducers in a type-safe way!
Async with Middleware - Learn how to make async calls, such as to a web service or local database, with Redux.
inKino App - A cross platform movie and showtime browser for Finnkino cinemas built with Redux. Lots of testing included as well!
flutter_architecture_samples - A Todo List App with local storage and multiple screens. Includes a README describing how to combine Redux with Flutter effectively.
redux_logging - Connects a Logger to a Store, and can print out actions as they're dispatched to your console.
redux_thunk - Allows you to dispatch functions that perform async work as actions.
redux_future - For handling Dart Futures that are dispatched as Actions.
redux_epics - Middleware that allows you to work with Dart Streams of Actions to perform async work.
Dev Tools
The redux_dev_tools library allows you to create a DevToolsStore during dev mode in place of a normal Redux Store.
This DevToolsStore will act exactly like a normal Store at first. However, it will also allow you to travel back and forth throughout the States of your app or recompute the State of your app by replaying all actions through your reducers. This works perfectly with Hot Reloading!
You can combine the DevToolsStore with your own UI to travel in time, or use one of the existing options for the platform you're working with:
reselect - Efficiently derive data from your Redux Store with memoized functions.
redux_persist - Persist Redux State, works for Web and Flutter
Usage
import'package:redux/redux.dart';
// Create typed actions. You will dispatch these in order to// update the state of your application.enumActions {
increment,
decrement,
}
// Create a Reducer. A reducer is a pure function that takes the // current State (int) and the Action that was dispatched. It should// combine the two into a new state without mutating the state passed// in! After the state is updated, the store will emit the update to // the `onChange` stream.// // Because reducers are pure functions, they should not perform any // side-effects, such as making an HTTP request or logging messages// to a console. For that, use Middleware.intcounterReducer(int state, action) {
if (action == Actions.increment) {
return state + 1;
} elseif (action == Actions.decrement) {
return state - 1;
}
return state;
}
// A piece of middleware that will log all actions with a timestamp// to your console!// // Note, this is just an example of how to write your own Middleware.// See the redux_logging package on pub for a pre-built logging // middleware.loggingMiddleware(Store<int> store, action, NextDispatcher next) {
print('${new DateTime.now()}: $action');
next(action);
}
main() {
// Create the store with our Reducer and Middlewarefinal store = newStore<int>(
counterReducer,
initialState: 0,
middleware: [loggingMiddleware],
);
// Render our State right awayrender(store.state);
// Listen to store changes, and re-render when the state is updated
store.onChange.listen(render);
// Attach a click handler to a button. When clicked, the `INCREMENT` action// will be dispatched. It will then run through the reducer, updating the // state.//// After the state changes, the html will be re-rendered by our `onChange`// listener above. querySelector('#increment').onClick.listen((_) {
store.dispatch(Actions.increment);
});
}
render(int state) {
querySelector('#value').innerHtml = '${state}';
}