Skip to content

null exception when calling getKey #3

@EbenZhang

Description

@EbenZhang

Describe the bug
null exception when calling getKey

E/flutter ( 4581): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter ( 4581): NoSuchMethodError: The method 'getStringList' was called on null.
E/flutter ( 4581): Receiver: null

To Reproduce
Steps to reproduce the behavior:

var cache = new CsCache();
cache.getKey("key");

Expected behavior

Able to call getKey without exception

Desktop (please complete the following information):

  • OS: Mint19
  • Version of this package: ^1.0.0

Smartphone (please complete the following information):

  • Device: Android emulator Pixel XL API 28, Android 9.0 (with Google APIs) x86

Additional context

I guess the getKey was called before the async _setSharedPref finished.

factory CsCache() {
......
     _singltonInstance._setSharedPref();
......
}
void _setSharedPref() async {
    _sharedPreferences = await SharedPreferences.getInstance();
}

BTW, using Flutter 1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions