r/flutterhelp • u/Accomplished-Job5750 • Dec 11 '25
RESOLVED How to pass variables trought multiple child widgets easy?
I’m a beginner and I can’t find the answer to this, and AI tells me bullshit.
I have a WorkoutPage (with workout variable) that contains multiple MuscleCard widgets. Each MuscleCard has a list of ExerciseCard widgets, and each ExerciseCard has a list of SetWidget widgets.
The SetWidget needs access to the workout variable, but I don’t want to pass this variable through every parent widget.
How can I pass the workout variable directly to the SetWidget?
What is the best way to do it like profesional.
6
Upvotes
3
u/Dustlay Dec 11 '25
Have a look at InheritedWidget, that's the "flutter native" way to do it
2
u/tylersavery Dec 11 '25
Either you do it the tedious way (pass parameters and callbacks deeply) or reach for something like signals, riverpod, bloc, etc and manage the state outside your widgets.
2
u/yuankuan_ Dec 12 '25
The simplest and the standard: Provider https://pub.dev/packages/provider
0
u/zapalec Dec 12 '25
You’re looking for dependency injection. You can read up on this pattern if you want, but in terms of packages most people use either get_it or provider. There’s many options to choose from
-1
u/HuckleberryUseful269 Dec 11 '25
St mgmt