title: Passing values from a Slider widget into firestore database
body: <p>I want to know what methods I can use to pass values from slider widget into a function linked to a firestore database. I have a list of values set to zero and the goal is to get the values to change when the slider's value is changed. Here is a snippet of the function:</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:flutter/material.dart';
  import 'package:wequilschool_app/screens/blend_&amp;_mix/item.dart';
  
  class SaveIngredientsProvider {
    /// Firestore database reference to the BlendandMix collection
    final CollectionReference blendAndMixDatabase =
        FirebaseFirestore.instance.collection(&quot;BlendandMix&quot;);
  
    /// Stores the item's objects
    List&lt;Item&gt; item = [];
  
    Future&lt;void&gt; updateIngredientCount() {
  
      // ignore: avoid_dynamic_calls
      return blendAndMixDatabase
          .doc('H2IbznvLGKYRvCLJSomk')
          .set({
            'ingredients': {
              'almond_butter': 0,
              'bananas': 0,
              'blackberries': 0,
              'blueberries': 0,
              'chia_seeds': 0,
              'chocolate_protein_powder': 0,
              'flax_seeds': 0,
              'greek_yogurt': 0,
              'ice_cubes': 0,
              'mango_chunks': 0,
              'mint': 0,
              'pineapple_chunks': 0,
              'raspberries': 0,
              'strawberries': 0,
              'vanilla_protein_powder': 0
            },
          }, SetOptions(merge: true))
          .then((value) =&gt; print(&quot;Ingrdient(s) Number Updated&quot;))
          .catchError(
              (error) =&gt; print(&quot;Failed to update ingredient count: $error&quot;));
    }
  }
  </code></pre>
  <p>Here is another snippet with the Slider widget:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:wequilschool_app/screens/blend_&amp;_mix/services/save_ingredients_provider.dart';
  
  /// Smoothie ingredient item
  
  class Item extends StatefulWidget {
    final String image;
    final String name;
    double saveValue = 0.0;
    double? defaultSaveValue = 0.0;
  
    /// Each item needs an image and name, so it is required
    Item({
      Key? key,
      required this.image,
      required this.name,
      this.defaultSaveValue,
    }) : super(key: key);
  
    @override
    _ItemState createState() =&gt; _ItemState();
  }
  
  class _ItemState extends State&lt;Item&gt; {
  
    @override
    Widget build(BuildContext context) {
      return Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Image.asset(
            widget.image,
            width: 70,
            fit: BoxFit.contain,
          ),
          Expanded(
            child: Text(&quot;${widget.name}&quot;, textAlign: TextAlign.center),
          ),
          Expanded(
              child: Slider(
            value: widget.defaultSaveValue ?? widget.saveValue,
            min: 0,
            max: 5,
            divisions: 5,
            label: widget.saveValue.toString(),
            onChanged: (double newValue) {
              setState(() {
                widget.defaultSaveValue = newValue;
                widget.saveValue = newValue;
              });
            },
          )),
          ElevatedButton(
              onPressed: () {
                SaveIngredientsProvider().updateIngredientCount();
              },
              child: const Text('Save Ingredients')),
        ],
      );
    }
  }
  </code></pre>