Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to make slider in flutter with API data?

I am trying to implement such logic in slider: i want to pull data from a map which looks like this: {min: 1, max: 16, value: 1.0, step: 1.0}. This data comes from API and I want to manipulate the slider with this data.
I did it like in code below, but nothing has happend:

  Slider(
          value: snapshot.data?['value'] ?? 0.toDouble(),
          activeColor: Colors.green,
          max: snapshot.data?['max'] ?? 0.toDouble(),
          min: snapshot.data?['min'] ?? 0.toDouble(),
          inactiveColor: Colors.green,
          label: values.toString(),
          onChanged: (double value) {
            var v = snapshot.data?['value'] ?? 0.toDouble();
            setState(() {
              v = value;
            });
          },
        ),

how can I achive this? Also it gives me an error:

type 'int' is not a subtype of type 'double'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Maybe the error come from api result so try do this:

Slider(
                        value: double.parse(snapshot.data?['value'].toString()?? '0'),
                        activeColor: Colors.green,
                        max: double.parse(snapshot.data?['max'].toString()?? '0')  ,
                        min: double.parse(snapshot.data?['min'].toString()?? '0'),
                        inactiveColor: Colors.green,
                        label: values.toString(),
                        onChanged: (double value) {
                          var v = double.parse(snapshot.data?['value'].toString()?? '0');
                          setState(() {
                            v = value;
                          });
                        },
                      )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading