title: how to close something before compiler thinks it is assigned a value, because closing can happen only in 2nd iteration of a loop
body: <p>I receive the error <code>The non-nullable local variable 'box' must be assigned before it can be used.</code> for the following code.</p>
  <pre class="lang-dart prettyprint-override"><code>int problemClass = -1;
  problems.forEach((p) async {
        if (p.problemClassId != problemClass) {
          if (problemClass != -1)
            box.close();
          box = await Hive.openBox(kProblemBoxNames[p.problemClassId]!);
          problemClass = p.problemClassId;
        }
  }      
  </code></pre>
  <p>I am opening a Hive box in the first iteration (<code>box.close()</code>cannot be executed because <code>problemClass == -1</code>). If <code>problemClass</code> does not change, the box remains unchanged in the 2nd iteration. However, if <code>problemClass</code> does change, the box currently open is closed and another box is opened.</p>
  <p>How do I get the compiler to understand my logic?!</p>