I'm beginner in flutter and provider. I managed to retrieve a value from a widget to the parent widget with provider. This value is an int.
Text( context.watch<EweProvider>().configSouteProvider,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25,
),
I would like to be able to do calculations with the int that I retrieve this way.
How to do it? Is that possible to do that directly with flutter without provider ?
THANKS
This is a part of my code
/// création de la classe a ecouter
class EweProvider extends ChangeNotifier {
var configSouteProvider;
var eweValueProvider;
EweProvider({
this.configSouteProvider = "0",
this.eweValueProvider = "0",
});
void changeconfigSouteProvider({required
String newConfigSoute,
}) async {
configSouteProvider = newConfigSoute;
notifyListeners();
}
void changeEweValueProvider({required
int newEweValue,
}) async {
eweValueProvider = newEweValue;
notifyListeners();
}
}
RadioMenuButton(
child: Text('14 sièges'),
value: '14 sièges',
groupValue: selectedConfigSoute,
onChanged: (selectValue){
setState(() {
selectedConfigSoute = selectValue!;
configSoute = 120;
context.read<EweProvider>().changeconfigSouteProvider(newConfigSoute: configSoute.toString());
calculEwe();
});
},
),
eweValueProviderand inchangeEweValueProvideryou are putting an int in it. Instead ofvar configSouteProvider;you should have a more specific type likeint configSouteProvider;otherwise you will get runtime errors when trying to assign different types to it