my_cookie.dart 3.1 KB

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