my_cookie.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/login_information_bean_entity.dart';
  3. import 'package:bbyyy/beans/user_bean_entity.dart';
  4. import 'package:bbyyy/my_tools/event_bus.dart';
  5. import 'package:disable_screenshots/disable_screenshots.dart';
  6. import 'package:package_info/package_info.dart';
  7. import 'package:shared_preferences/shared_preferences.dart';
  8. String appName = '梆梆鱼';
  9. class MyCookie {
  10. MyCookie._internal() {
  11. // initP();
  12. }
  13. //保存单例
  14. static MyCookie _singleton = new MyCookie._internal();
  15. //工厂构造函数
  16. factory MyCookie() => _singleton;
  17. // String server = '172.16.104.19';
  18. String server = 'bby.banghuo.net';
  19. // String server = '39.108.225.84';
  20. SharedPreferences prefs;
  21. PackageInfo packageInfo;
  22. UserBeanDataData userBean;
  23. DisableScreenshots plugin;
  24. MyLocation location;
  25. bool haveNoPay = false;
  26. bool underReview = true;
  27. bool switching = false;
  28. int reNum = 0;
  29. getUT() {
  30. return 'user=${loginInformation.data.user}&token=${loginInformation.data.token}';
  31. }
  32. getServer() {
  33. return 'http://$server:3001';
  34. }
  35. initP() async {
  36. prefs = await SharedPreferences.getInstance();
  37. if(prefs.getString('serverID')==null||prefs.getString('serverID').isEmpty){
  38. prefs.setString('serverID', '0');
  39. }
  40. packageInfo = await PackageInfo.fromPlatform();
  41. EventBus().emit('packageInfo');
  42. plugin = DisableScreenshots();
  43. if (prefs.getBool('收入进账提示音') == null) {
  44. prefs.setBool('收入进账提示音', true);
  45. }
  46. if (prefs.getBool('聊天新消息提示音') == null) {
  47. prefs.setBool('聊天新消息提示音', true);
  48. }
  49. }
  50. LoginInformationBeanEntity loginInformation;
  51. saveLoginInformationBeanEntity(
  52. LoginInformationBeanEntity loginInformationBeanEntity) {
  53. prefs.setString(
  54. 'LoginInformationBeanEntity', json.encode(loginInformationBeanEntity));
  55. loginInformation = loginInformationBeanEntity;
  56. }
  57. LoginInformationBeanEntity getLoginInformation() {
  58. if (loginInformation == null) {
  59. try {
  60. loginInformation = LoginInformationBeanEntity().fromJson(
  61. json.decode(prefs.getString('LoginInformationBeanEntity')));
  62. } catch (e) {
  63. return null;
  64. }
  65. return loginInformation;
  66. } else {
  67. return loginInformation;
  68. }
  69. }
  70. getUser() {
  71. return loginInformation.data.user;
  72. }
  73. String getToken() {
  74. return loginInformation.data.token;
  75. }
  76. getUID() {
  77. return loginInformation.data.extra.uid;
  78. }
  79. clean() {
  80. loginInformation = null;
  81. prefs.remove('LoginInformationBeanEntity');
  82. // prefs.clear();
  83. }
  84. String getName() {
  85. return loginInformation.data.extra.name;
  86. }
  87. String getPic() {
  88. return loginInformation.data.extra.picture;
  89. }
  90. }
  91. class MyLocation{
  92. String province;
  93. String city;
  94. String formattedAddress;
  95. String district;
  96. double latitude;
  97. double longitude;
  98. MyLocation(
  99. {this.province,
  100. this.city,
  101. this.district,
  102. this.formattedAddress,
  103. this.latitude,
  104. this.longitude});
  105. }