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

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

class TokenProvider extends ChangeNotifier {
  TokenProvider() {
    loadToken();
  }

  LoginBean _loginBean;

  bool get isLogin => _loginBean != null;

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

  clearToken() {
    _loginBean = null;
    notifyListeners();
  }

  setToken(LoginBean lb) {
    _loginBean = lb;
    notifyListeners();
  }
}
