title: Flutter Shared Preferences Issue
body: <p>I have a simple Flutter function to get a counter from shared preferences, increment it, and save it back to shared preferences. It's in a separate file because I'm going to add more code and call it from several screens. The problem is that the counter value does not persist when I restart the app. I suspect the issue is the scope of my counter variable, but I don't know how to fix it.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import 'package:shared_preferences/shared_preferences.dart';
  
  var fileName = 'Counter';
  int counter;
  
  updateCounter() {
  
    getCounter(counter) async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      counter = (prefs.getInt('$fileName') ?? 0);
    }
  
    putCounter(counter) async {
      SharedPreferences preferences = await   SharedPreferences.getInstance();
      preferences.setInt('$fileName', counter);
      );
    }
  
    getCounter(counter);
    if (counter == null) {
      counter = 0;
    }
    counter++;
    putCounter(counter);
  
  }
  </code></pre>