title: Flutter SharedPreferences Null check operator used on a null value
body: <p>I've made a class for shared preferences. The class is as follows</p>
  <pre><code>class StorageUtil {
    static StorageUtil? _storageInstance;
    static SharedPreferences? _preferences;
  
    static Future&lt;StorageUtil?&gt; getInstance() async {
      if (_storageInstance == null) {
        _storageInstance = StorageUtil();
      }
      if (_preferences == null) {
        _preferences = await SharedPreferences.getInstance();
      }
      return _storageInstance;
    }
  
    addStringtoSF(String key, String value) async {
      print(' inside sharedPreferences file $key $value'); // Receives data here
      await _preferences!.setString(key,
          value); //Unhandled Exception: Null check operator used on a null value
    }
  </code></pre>
  <p>When ever i try to store the values i'm getting a error 'Null check operator used on a null value'</p>
  <p>This is how i'm passing down the values to the store function. I'm receiving the data inside the function. But cannot store the values inside it. What causes this?</p>
  <pre><code>String? userResponse = json.encode(authResponse);
        print('This is userResponse type');
        _storageUtil.addStringtoSF('userData', userResponse);
  </code></pre>