title: Flutter Initializing Variable before building the Widget
body: <p>i'am trying to get a &quot;Water Meter&quot; going.
  When i'am opening the App the Value for this should be generated.
  My problem here is that when i am building the Widget it doesn't Render the actual value.
  Only if i go to another Screen or Hot Reload the screen it renders out the value.
  Here i calculate and set the State.</p>
  <pre><code>    var dif = parsedDate.difference(dateNow).inDays;
  
      var difInPercent = double.parse((dif / interval).toStringAsFixed(2));
  
      setState(() {
        waterPercentage = difInPercent*100;
      });
  
      print(waterPercentage); // for debug purposes
  </code></pre>
  <p>And later in my Build method i use this Variable i defined globally for my Widget</p>
  <pre><code>Container(
       height: waterPercentage,
       width: 15,
  [...]
  </code></pre>
  <p>Obviously i'am doing something wrong because the state is not set directly.
  The Function which runs this set State &quot;plantDate()&quot; gets called in another widget.</p>
  <pre><code>Text(
     &quot;Next watering: \n${plantDate(widget.plant.date, widget.plant.interval)}&quot;,
  [...]
  </code></pre>
  <p>Anyone got an idea ?</p>
  <p>EDIT: Here is the Code for the complete Class <a href="https://pastebin.com/N4M55YnA" rel="nofollow noreferrer">https://pastebin.com/N4M55YnA</a></p>
  <p>EDIT2: Did it like that but it doesn't work like that.</p>
  <pre><code>@override
   initState(){
     super.initState();
     interval = widget.plant.interval;
     parsedDate = DateTime.parse(date);
     date = DateFormat.MMMMd().format(parsedDate);
  
     var dateNow = DateTime.now();
     var dif = parsedDate.difference(dateNow).inDays;
     var difInPercent = double.parse((dif / interval).toStringAsFixed(2));
     waterPercentage = difInPercent*100;
   }
  </code></pre>