Flutter sharedPreferences使用

  # sp键值存储
  shared_preferences: ^0.5.1+2
  Future setUserToken() async{
     SpUtil spUtil = await SpUtil.getInstance();
     spUtil.putString(SharedPreferencesKeys.userToken, '10');
  }

  Future delUserToken() async{
    SpUtil spUtil = await SpUtil.getInstance();
    spUtil.remove(SharedPreferencesKeys.userToken);
  }

  Future getUserToken() async{
    SpUtil spUtil = await SpUtil.getInstance();
    String userToken =  spUtil.get(SharedPreferencesKeys.userToken);
    print('------获得结果 $userToken-----');
  }
屏幕快照 2019-04-09 下午7.47.20.png

你可能感兴趣的:(Flutter sharedPreferences使用)