my_cookie.dart 2.8 KB

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