I want to share values among classes

Asked 2 years ago, Updated 2 years ago, 111 views

I want to use the variable value (genreID) defined in A.dart in B.dart.
How should I set it up?
Some [A.dart] calculations are left out to [B.dart], not screen transitions.
This is the ??? part of the diagram.

flutter dart

2022-09-29 21:59

1 Answers

The following article by Momo is easy to understand in detail
https://medium.com/flutter-jp/state-1daa7fd66b94

I recommend the official document because it is explained in a very easy-to-understand way^^
https://flutter.dev/docs/development/data-and-backend/state-mgmt/options

·InheritedWidget
·BLoC
·Provider+StateNotifier/ChangeNotifier

and so on…
Too many state management techniques lol

In my personal opinion, the in-screen processing is done with setState or RiverPod.
As for the cross-screen condition, I think StateNotifier+Provider+freezed is good for now
Flutter still has a lot of destructive changes, so I can't say it's true if I use it
Provider is officially recommended, and is somewhat easy to understand, so I recommend it

Here's an example code: https://flutter.dev/docs/development/data-and-backend/state-mgmt/simple


2022-09-29 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.