title: Flutter can't preserve stateful state when exit showModalBottomSheet and show showModalBottomSheet again
body: <p>So I have the following code to showModalBottomSheet, and display filters/checkboxes on the page. If I exit the modal and show the showModalBottomSheet again, then I don't see the checkbox values got preserved.</p>
  <p>It seems the 2nd time I show the modal, the build() from _CheckboxStatefulWidgetState was called again, and then default the checkValue to null.</p>
  <p>Here is <code>filter.dart</code></p>
  <pre><code>import 'package:flutter/material.dart';
  import '../helper/checkbox.dart';
  
  mixin ListFilter&lt;T extends StatefulWidget&gt; on State&lt;T&gt; {
  
    dynamic filters = [
      {
        &quot;name&quot;: &quot;name1&quot;,
        &quot;choices&quot;: [
          {'label': 'label1', 'value': 'value1', 'check': false},
          {'label': 'label2', 'value': 'value2', 'check': false},
        ],
      },
      {
        &quot;name&quot;: &quot;nameA&quot;,
        &quot;choices&quot;: [
          {'label': 'labelA', 'value': 'valueA', 'check': false},
          {'label': 'labelB', 'value': 'valueB', 'check': false},
        ],
      },
    ];
  
    dynamic filterWidgets;
  
    void showFilterModal(context, dynamic filters) {
      showModalBottomSheet&lt;void&gt;(
        context: context,
        //isScrollControlled: true,
        builder: (BuildContext context) {
          if (filterWidgets == null) {
            print(&quot;----&gt; filterWidgets is null&quot;);
            filterWidgets = _getFilterWidgets(filters);
          }
          return Container(
            child: Center(
              child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: filterWidgets),
            ),
          );
        },
      );
    }
  
    List&lt;Widget&gt; _getFilterWidgets(dynamic filters) {
      List&lt;Widget&gt; children = [];
  
      for (var i = 0; i &lt; filters.length; i++) {
        dynamic filter = filters[i];
        dynamic choices = filter['choices'];
  
        for (var j = 0; j &lt; choices.length; j++) {
          dynamic choice = choices[i];
          children.add(CheckboxStatefulWidget(
              label: choice['label']));
        }
  
        Widget divider = Divider();
        children.add(divider);
      }
  
      return children;
    }
  }
  </code></pre>
  <p>Here is <code>checkbox.dart</code></p>
  <pre><code>import 'package:flutter/material.dart';
  
  
  class CheckboxStatefulWidget extends StatefulWidget {
    final String label;
  
    CheckboxStatefulWidget({Key key, this.label}) : super(key: key);
  
    @override
    _CheckboxStatefulWidgetState createState() =&gt;
        _CheckboxStatefulWidgetState();
  }
  
  class _CheckboxStatefulWidgetState extends State&lt;CheckboxStatefulWidget&gt; {
  
    bool checkValue;
  
    @override
    Widget build(BuildContext context) {
  
      print(&quot;checkValue: $checkValue&quot;);
      print(checkValue == true ?? false);
  
      return CheckboxListTile(
          title: Text(this.widget.label),
          value: checkValue == true ?? false,
          onChanged: (bool newValue) {
            setState(() {
              checkValue = newValue;
            });
          });
    }
  }
  </code></pre>