I’m new to Flutter and have spent numerous time going over tutorials and google io talks about state administration and determined to make use of supplier in my chat app that additionally makes use of Google Cloud Firestore because the backend for all the things from auth to sending and retrieving messages. I’ve needed to rebuild the app from scratch twice already resulting from design errors.
Right here is how my app presently works and is that this utilizing supplier proper or incorrect?
Right here is my larger stage widget tree
Foremost -> Supplier // Backend to let me join and sign up with firebase
—Little one is: StreamProvider FirebaseUser.worth(FirebaseAuthService.onAuthStateChanged)
—Little one is: Shopper FirebaseUser
—Little one is: Supplier FirestoreService which takes worth of signed in consumer and does all my actions akin to creating and becoming a member of group chat for consumer and sending message for consumer
—Little one is: Shopper FirestoreService
—Little one is: StreamProvider Consumer.worth(worth: userService.getUserProfileStream()) // This streams from consumer doc in firestore which is created after consumer indicators up account
—Little one is: Shopper Consumer // My customized consumer mannequin
—Little one is: ChangeNotifierProvider ValueNotifier bool // Wraps my group
chats listing and messages web page, if true reveals group chats listing, if false reveals the messages for the group chat web page was chosen
—Little one is: StreamBuilder Iterable GroupChat (stream: firestoreService.getGroupChatsStream()) // I stream any modifications to group chats paperwork from firestore for consumer
—Little one is: Selector ValueNotifier bool, bool // if true reveals group chats listing, if false reveals the messages for the group chat web page was chosen
—Little one is: Group Chats listing web page if selector true
—Little one is: Message Web page if false
How I am utilizing Supplier
— Proper now I combine StateFull widgets with code that listens to my supplier modifications is that this incorrect? Ought to I solely use stateless widgets in courses with supplier and put all of the variables that require state into some change notifier mannequin class.
— As an alternative of web page routes I additionally use supplier to change between the pages in my app be deciding what widget will get rendered by means of some selector boolean. Is that this incorrect ought to i simply use web page routes as an alternative? I felt with web page routes they did not have the identical ancestor as the place i pushed them for supplier to work correctly.
— Plenty of the streams and shoppers and selectors above are all in the identical class, ought to i make every supplier be in its personal stateless widget or is it advantageous to have suppliers and selectors be in the identical stateless or statefull widget.