import 'package:fengshui_compass/utils/sp_utils.dart';

import '../models/login_bean.dart';

class TokenHelper {
  TokenHelper._();

  static TokenHelper getInstance = TokenHelper._();

  LoginBean _loginBean;

  bool get isLogin => _loginBean != null;

  set loginBean(LoginBean bean) {
    _loginBean = bean;
    SPUtil.saveObject("token_bean", _loginBean);
  }

  void init() {
    Map<String, dynamic> map = SPUtil.getObject("token_bean");
    if (map != null) {
      //加载缓存
      _loginBean = LoginBean.fromMap(map);
    }
  }

  void clear() {
    _loginBean = null;
    SPUtil.remove("token_bean");
  }
}
