title: Switch/Checkbox not updating on setState()
body: <p>I've been doing this for 4 days, reading half of the Google and watching 3/4 of Youtube. I have a list of objects, I'm getting data from API. When those objects get generated into cards, Switch of Checkbox are not functiona, setState does not affect them at all. This is the original code, before I started trying things and messing up the code (thank you for Git).</p>
  <p>Anyone got any ideas?</p>
  <pre><code>import 'dart:convert';
  import 'dart:developer';
  
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  import 'package:mojmegatel/API/get_settings_api.dart';
  import 'package:mojmegatel/api/set_settings_api.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  import 'package:flutter_spinkit/flutter_spinkit.dart';
  
  import '../constants.dart';
  import 'dart:io';
  
  class SettingsArray extends StatefulWidget {
    final ValueChanged onChanged;
    final bool isSwitched;
  
    const SettingsArray({
      required this.onChanged,
      required this.isSwitched,
      Key? key,
    }) : super(key: key);
  
    @override
    _SwitchWidget createState() =&gt; _SwitchWidget();
  }
  
  class _SwitchWidget extends State&lt;SettingsArray&gt; {
    Future? dataFuture;
    bool isSwitched = false;
  
    @override
    void initState() {
      isSwitched = false;
      dataFuture = _getData();
  
      super.initState();
    }
  
    _getData() async {
      await GetSettings();
  
      SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
  
      String sharedPrefsSettings = sharedPrefs.getString('settings').toString();
      String jsonSettings = await DefaultAssetBundle.of(context).loadString(&quot;assets/json/settings_data.json&quot;);
  
      String mergedData = await MergeData(jsonSettings, sharedPrefsSettings);
      return mergedData;
    }
  
    Future&lt;String&gt; MergeData(String jsonSettings, String sharedPrefsSettings) async {
      var decodedJsonSettings = json.decode(jsonSettings);
      var decodedSharedPrefsSettings = json.decode(sharedPrefsSettings);
  
      String mergedSettings = '[';
  
      bool found_id = false;
      bool is_last = false;
  
      String service_id;
      String name;
      String description;
      String servicerequestvalue;
  
      for (int i = 0; i &lt; decodedJsonSettings.length; i++) {
        for (int j = 0; j &lt; decodedSharedPrefsSettings.length; j++) {
          if (decodedJsonSettings[i]['service_id'] == decodedSharedPrefsSettings[j]['service_id']) {
            found_id = true;
  
            service_id = decodedJsonSettings[i]['service_id'];
            name = decodedJsonSettings[i]['title'];
            description = decodedJsonSettings[i]['description'];
            servicerequestvalue = decodedSharedPrefsSettings[j]['servicerequestvalue'];
  
            mergedSettings += '{&quot;service_id&quot;: &quot;$service_id&quot;,';
            mergedSettings += '&quot;name&quot;: &quot;$name&quot;,';
            mergedSettings += '&quot;description&quot;: &quot;$description&quot;,';
            mergedSettings += '&quot;servicerequestvalue&quot;: &quot;$servicerequestvalue&quot;}';
  
            if (i == decodedJsonSettings.length - 1 &amp;&amp; j == decodedSharedPrefsSettings.length - 1) {
              // Nothing, don't complicate
            } else {
              mergedSettings += ',';
            }
          }
        }
  
        if (found_id == false) {
          service_id = decodedJsonSettings[i]['service_id'];
          name = decodedJsonSettings[i]['title'];
          description = decodedJsonSettings[i]['description'];
  
          mergedSettings += '{&quot;service_id&quot;: &quot;$service_id&quot;,';
          mergedSettings += '&quot;name&quot;: &quot;$name&quot;,';
          mergedSettings += '&quot;description&quot;: &quot;$description&quot;,';
          mergedSettings += '&quot;servicerequestvalue&quot;: &quot;0&quot;}';
  
          if (i == decodedJsonSettings.length - 1) {
            // Nothing, don't complicate
          } else {
            mergedSettings += ',';
          }
        } else {
          found_id = false;
        }
      }
  
      mergedSettings += ']';
  
      return mergedSettings;
    }
  
    Widget build(BuildContext context) {
      List&lt;Widget&gt; widgetList = &lt;Widget&gt;[];
  
      return ListView.builder(
        shrinkWrap: true,
        physics: ScrollPhysics(),
        itemCount: 1,
        itemBuilder: (context, index) {
          return FutureBuilder(
            future: dataFuture,
            builder: (context, snapshot) {
              if (snapshot.data != null) {
                String service_id;
                String name;
                String description;
  
                var settingsData = json.decode(snapshot.data.toString());
  
                List&lt;dynamic&gt; list = settingsData;
                widgetList = &lt;Widget&gt;[];
  
                for (int i = 0; i &lt; list.length; i++) {
                  String serviceRequestValue = settingsData[i]['servicerequestvalue'].toString();
                  bool serviceRequestValueBool = true;
  
                  service_id = settingsData[i]['service_id'].toString();
                  name = settingsData[i]['name'].toString();
                  description = settingsData[i]['description'].toString();
  
                  log(service_id);
  
                  if (serviceRequestValue == &quot;1&quot; || serviceRequestValue == &quot;1,1&quot; || serviceRequestValue == &quot;14&quot;) {
                    serviceRequestValueBool = true;
                  } else {
                    serviceRequestValueBool = false;
                  }
  
                  widgetList.add(settingsContainer(service_id, service_id, name, description, serviceRequestValueBool));
                }
  
                return Column(children: widgetList.toList());
              }
  
              return Column(
                children: [
                  Container(
                    width: 60.0,
                    height: 80.0,
                    padding: EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 0.0),
                    child: SpinKitFoldingCube(color: MojMegaTelTheme.megaTelBlue), // CircularProgressIndicator(),
                  ),
                ],
              );
            },
          );
        },
      );
    }
  
    Widget settingsContainer(String key, String serviceId, String title, String description, bool isSwitched) {
      return Padding(
        key: ValueKey(key),
        padding: const EdgeInsets.only(left: 24, right: 24, top: 16, bottom: 18),
        child: Container(
          decoration: BoxDecoration(
            color: MojMegaTelTheme.white,
            borderRadius: BorderRadius.only(topLeft: Radius.circular(8.0), bottomLeft: Radius.circular(8.0), bottomRight: Radius.circular(8.0), topRight: Radius.circular(8.0)),
            boxShadow: &lt;BoxShadow&gt;[
              BoxShadow(color: MojMegaTelTheme.grey.withOpacity(0.2), offset: Offset(1.1, 1.1), blurRadius: 10.0),
            ],
          ),
          child: Column(
            children: &lt;Widget&gt;[
              Padding(
                padding: const EdgeInsets.only(top: 16, left: 16, right: 24),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: &lt;Widget&gt;[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: &lt;Widget&gt;[
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: &lt;Widget&gt;[
                            Padding(
                              padding: const EdgeInsets.only(left: 4, bottom: 3),
                              child: Row(
                                children: [
                                  Text(
                                    title,
                                    overflow: TextOverflow.fade,
                                    maxLines: 1,
                                    softWrap: false,
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                      fontFamily: MojMegaTelTheme.fontName,
                                      fontWeight: FontWeight.w600,
                                      fontSize: 14,
                                      color: MojMegaTelTheme.darkerText,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            Padding(
                              padding: const EdgeInsets.only(left: 8),
                              child: Row(
                                children: [
                                  Checkbox(
                                    value: isSwitched,
                                    onChanged: (value) {
                                      setState(
                                        () {
                                          isSwitched = value!;
                                          log(&quot;Swich: &quot; + isSwitched.toString());
                                        },
                                      );
                                    },
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ],
                    )
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 24, right: 24, top: 8, bottom: 8),
                child: Container(
                  height: 2,
                  decoration: BoxDecoration(
                    color: MojMegaTelTheme.background,
                    borderRadius: BorderRadius.all(Radius.circular(4.0)),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 24, right: 24, top: 8, bottom: 16),
                child: Row(
                  children: &lt;Widget&gt;[
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: &lt;Widget&gt;[
                          Padding(
                            padding: const EdgeInsets.only(top: 6),
                            child: Text(
                              description,
                              textAlign: TextAlign.left,
                              style: TextStyle(
                                fontFamily: MojMegaTelTheme.fontName,
                                fontWeight: FontWeight.w600,
                                fontSize: 12,
                                color: MojMegaTelTheme.grey.withOpacity(0.5),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
      );
    }
  }
  </code></pre>