title: Flutter - add together the number of SwitchListTile = true
body: <p>I have an app I'm working on.  It sounds simple in theory of what I want to do, but just cannot make it work.</p>
  <p>I want to output Text of how many of the SwitchLiStTile's are true.  There are 8 SwitchListTiles, if someone clicks the 3rd and 5th ones, I want the output to be 2.  I cannot grasp how I would accomplish this.  Everything I have tried has failed.  If I could just make the value of the Switch an integer, this would be simple.</p>
  <pre><code>removed 1st example code
  </code></pre>
  <p>Granted, if there was truly on 2 switches, this would be way easier.  There are 8 (4 in this example) and will be more.  This is just shorthand code because I felt I needed to put something.  How would I go about getting this solved?  I have tried converting the Bools to integers and that just adds more problems.  I Can't just use a Dart Operator to add them together when they are not integers anyways.  Nothing seems to work without writing line after line, within a HUGE if statement.  I'm working with 8 switches which give a huge number of possibilities.
  Any help would be awesome.</p>
  <p>*** OK so I am going to add some simple code and try and explain what I am doing and what I want.
  I'll go ahead and add the 3 files I'm using.</p>
  <p>main.dart</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'result.dart';
  import 'data.dart';
  
  void main() {
  runApp(MyApp());
  }
  
  class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
  return MaterialApp(
    title: 'TestApp',
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    home: const MyHomePage(),
  );
  }
  }
  
  class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);
  
  @override
  State&lt;MyHomePage&gt; createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
  int cluecounter = 0;
  
  final wat = [
  false,
  false,
  false,
  false,
  </code></pre>
  <p>];</p>
  <pre><code>final _formKey = GlobalKey&lt;FormState&gt;();
  final _user = User();
  @override
  Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('TestApp'),
    ),
    body: SingleChildScrollView(
      padding: EdgeInsets.all(16.0),
      child: Builder(
        builder: (context) =&gt; Form(
          key: _formKey,
          child: Container(
            child: Column(
              children: [
                Text('Just A Test'),
                SwitchListTile(
                    title: const Text('SwitchListTile 1'),
                    value: _user.wat1,
                    onChanged: (bool val) {
                      return setState(() {
                        if (_user.wat1 == true) {
                          cluecounter--;
                        } else {
                          cluecounter++;
                        }
                        _user.wat1 = val;
                      });
                    }),
                SwitchListTile(
                    title: const Text('SwitchListTile 2'),
                    value: _user.wat2,
                    onChanged: (bool val) {
                      return setState(() {
                        if (_user.wat2 == true) {
                          cluecounter--;
                        } else {
                          cluecounter++;
                        }
                        _user.wat2 = val;
                      });
                    }),
                SwitchListTile(
                    title: const Text('SwitchListTile 3'),
                    value: _user.wat3,
                    onChanged: (bool val) {
                      return setState(() {
                        if (_user.wat3 == true) {
                          cluecounter--;
                        } else {
                          cluecounter++;
                        }
                        _user.wat3 = val;
                      });
                    }),
                SwitchListTile(
                    title: const Text('SwitchListTile 4'),
                    value: _user.wat4,
                    onChanged: (bool val) {
                      return setState(() {
                        if (_user.wat4 == true) {
                          cluecounter--;
                        } else {
                          cluecounter++;
                        }
                        _user.wat4 = val;
                      });
                    }),
                Text(
                  'counter value: $cluecounter\n',
                  textAlign: TextAlign.center,
                ),
                FloatingActionButton.extended(
                  backgroundColor: const Color(0xff364976),
                  foregroundColor: const Color(0xffffffff),
                  onPressed: () {
                    final form = _formKey.currentState;
                    form?.save();
                    _user.save();
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) =&gt; 
  Result(user:this._user),
                      ),
                    );
                  },
                  icon: Icon(Icons.arrow_forward),
                  label: Text(' Save'),
                ),
              ],
            ),
          ),
        ),
      ),
    ),
   );
  }
  }
  </code></pre>
  <p>result.dart</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'data.dart';
  
  class Result extends StatelessWidget {
  User user;
  Result({Key? key, required this.user}) : super(key: key);
  
  
  @override
  Widget build(BuildContext context) {
  
  return Scaffold(
    appBar: AppBar(
      title: const Text('Results'),
    ),
    body: SingleChildScrollView(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text('THE RESULTS'),
          if (user.wat1 == true)
            const Text(
              'Switch 1 is True',
              style: TextStyle(fontSize: 16),
            ),
          if (user.wat2 == true)
            const Text(
              'Switch 2 is True',
              style: TextStyle(fontSize: 16),
            ),
          if (user.wat3 == true)
            const Text(
              'Switch 3 is True',
              style: TextStyle(fontSize: 16),
            ),
          if (user.wat4 == true)
            const Text(
              'Switch 4 is True',
              style: TextStyle(fontSize: 16),
            ),
          Text('\n\nSwitch Count &gt;&gt;   I WANT THE COUNT HERE   &lt;&lt;'
          ),
        ],
      ),
    ),
   );
  }
  }
  </code></pre>
  <p>and the models
  data.dart</p>
  <pre><code>class User {
  
  bool wat1 = false;
  bool wat2 = false;
  bool wat3 = false;
  bool wat4 = false;
  
  save() {}
  }
  </code></pre>
  <p>On the results, I want to see a count of how many switches are true.</p>