0

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();
                });
              },
            ),
1
  • In any case you should have it the right type. In the constructor you are putting a String in eweValueProvider and in changeEweValueProvider you are putting an int in it. Instead of var configSouteProvider; you should have a more specific type like int configSouteProvider; otherwise you will get runtime errors when trying to assign different types to it Commented Dec 3, 2024 at 9:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.