import 'dart:convert';
import 'package:flustars/flustars.dart';

class SaveModel {
  // factory UserData() => getInstance();
  // static UserData get instance => getInstance();
  // static UserData _instance;
  //
  // static UserData getInstance() {
  //   if (_instance == null) {
  //     _instance = new UserData._internal();
  //   }
  //   return _instance;
  // }
  //
  // UserData._internal() {
  //
  // }

  static saveModel(dynamic model,String modelName) {
    //将data转换成json字符串
    var jsonStr = json.encode(model);
    SpUtil.putString(modelName, jsonStr);
  }

  // 读取 SharedPreferences
  static getModel(String modelName) {
    final jsonStr = SpUtil.getString(modelName);
    if(jsonStr != null && jsonStr.length > 0){
      //先将json字符串转json
      Map json = jsonDecode(jsonStr);
      return json;
    }
    return null;
  }

  static removeModel(String modelName){
    SpUtil.putString(modelName,"");
  }
}