my_cookie.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. double balance;
  26. MyLocation location;
  27. bool haveNoPay = false;
  28. bool underReview = true;
  29. bool switching = false;
  30. int reNum = 0;
  31. getUT() {
  32. return '${MyApis.getApi('user')}=${loginInformation.data.user}&${MyApis.getApi('token')}=${loginInformation.data.token}';
  33. }
  34. getServer() {
  35. return 'https://$server:4001';
  36. }
  37. initP() async {
  38. prefs = await SharedPreferences.getInstance();
  39. if(prefs.getString('serverID')==null||prefs.getString('serverID').isEmpty){
  40. prefs.setString('serverID', '0');
  41. }
  42. packageInfo = await PackageInfo.fromPlatform();
  43. EventBus().emit('packageInfo');
  44. plugin = DisableScreenshots();
  45. if (prefs.getBool('收入进账提示音') == null) {
  46. prefs.setBool('收入进账提示音', true);
  47. }
  48. if (prefs.getBool('聊天新消息提示音') == null) {
  49. prefs.setBool('聊天新消息提示音', true);
  50. }
  51. }
  52. LoginInformationBeanEntity loginInformation;
  53. saveLoginInformationBeanEntity(
  54. LoginInformationBeanEntity loginInformationBeanEntity) {
  55. prefs.setString(
  56. 'LoginInformationBeanEntity', json.encode(loginInformationBeanEntity));
  57. loginInformation = loginInformationBeanEntity;
  58. }
  59. LoginInformationBeanEntity getLoginInformation() {
  60. if (loginInformation == null) {
  61. try {
  62. loginInformation = LoginInformationBeanEntity().fromJson(
  63. json.decode(prefs.getString('LoginInformationBeanEntity')));
  64. } catch (e) {
  65. return null;
  66. }
  67. return loginInformation;
  68. } else {
  69. return loginInformation;
  70. }
  71. }
  72. getUser() {
  73. return loginInformation.data.user;
  74. }
  75. String getToken() {
  76. return loginInformation.data.token;
  77. }
  78. getUID() {
  79. return loginInformation.data.extra.uid;
  80. }
  81. clean() {
  82. loginInformation = null;
  83. prefs.remove('LoginInformationBeanEntity');
  84. // prefs.clear();
  85. }
  86. String getName() {
  87. return loginInformation.data.extra.name;
  88. }
  89. String getPic() {
  90. return loginInformation.data.extra.picture;
  91. }
  92. }
  93. class MyLocation{
  94. String province;
  95. String city;
  96. String formattedAddress;
  97. String district;
  98. double latitude;
  99. double longitude;
  100. MyLocation(
  101. {this.province,
  102. this.city,
  103. this.district,
  104. this.formattedAddress,
  105. this.latitude,
  106. this.longitude});
  107. }