title: How do I increment a counter and disable a button in Flutter?
body: <p>I have a button I want to disable after incrementing my counter. This is the method I'm using to increment my counter:</p>
  
  <pre><code>void incrementAdCounter() async {
      setState(() {
        adCounter++;
        if (adCounter == 2 || adCounter &gt; 2) {
          isAdButtonDisabled = true;
        }
        setAdCounter();
        print(adCounter);
      });
    }
  </code></pre>
  
  <p>Inside initState: </p>
  
  <pre><code>void initButtons() {
      isAdButtonDisabled = false;
      adCounter = 0
  }
  </code></pre>
  
  <p>I have a button and I've called these methods on the onTap if the buttons: </p>
  
  <pre><code>void getCounters() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    adCounter = prefs.getInt('adCounter');
    isAdButtonDisabled = prefs.getBool('isAdButtonDisabled');
  }
  setAdCounter() async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      prefs.setInt('adCounter', adCounter);
      prefs.setBool('isAdButtonDisabled', isAdButtonDisabled);
    }
  </code></pre>
  
  <p>When I call this method it shows me the following error:</p>
  
  <pre><code>Unhandled Exception: NoSuchMethodError: The method '+' was called on null.
  E/flutter (13166): Receiver: null
  </code></pre>