基础库
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

86 行
2.8 KiB

  1. import 'dart:io';
  2. import 'dart:convert';
  3. import 'package:zhiying_comm/util/net_util.dart';
  4. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  5. import 'package:zhiying_comm/zhiying_comm.dart';
  6. class BaseSettingModel {
  7. String fileProvider;
  8. String fileBucketHost;
  9. String fileBucketHostProtocol;
  10. String isIosReview;
  11. Map<String, dynamic> tab;
  12. static BaseSettingModel _setting;
  13. static BaseSettingModel get setting {
  14. if (_setting == null) {
  15. Logger.error('暂未初始化');
  16. }
  17. return _setting;
  18. }
  19. BaseSettingModel({this.fileProvider, this.fileBucketHost, this.fileBucketHostProtocol});
  20. BaseSettingModel.fromJson(Map<String, dynamic> json) {
  21. fileProvider = json['file_provider'];
  22. fileBucketHost = json['file_bucket_host'];
  23. fileBucketHostProtocol = json['file_bucket_host_protocol'];
  24. isIosReview = json['is_ios_review']?.toString();
  25. tab = Map<String, dynamic>.from(json['bottom_nav']);
  26. }
  27. Map<String, dynamic> toJson() {
  28. final Map<String, dynamic> data = new Map<String, dynamic>();
  29. data['file_provider'] = this.fileProvider;
  30. data['file_bucket_host'] = this.fileBucketHost;
  31. data['file_bucket_host_protocol'] = this.fileBucketHostProtocol;
  32. data['bottom_nav'] = this.tab;
  33. data['is_ios_review'] = this.isIosReview;
  34. return data;
  35. }
  36. static Future<BaseSettingModel> init({bool isGetCache}) async {
  37. try {
  38. ///判断是否获取缓存
  39. if (isGetCache != null && isGetCache) {
  40. String configData = await SharedPreferencesUtil.getStringValue(GlobalConfig.MAIN_CONFIG, defaultVal: '1');
  41. if (configData != "1") {
  42. _setting = BaseSettingModel.fromJson(Map<String, dynamic>.from(json.decode(configData)));
  43. if (Platform.isIOS) {
  44. if (null != _setting && _setting.isIosReview == '1') {
  45. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '1');
  46. } else {
  47. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '0');
  48. }
  49. }
  50. Logger.debug('基础设置初始化');
  51. }
  52. NetUtil.request('/api/v1/new/config.json',onSuccess: (data){
  53. });
  54. } else {
  55. Map result =
  56. await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET);
  57. var data = result['data'];
  58. _setting = BaseSettingModel.fromJson(Map<String, dynamic>.from(data));
  59. if (Platform.isIOS) {
  60. if (null != _setting && _setting.isIosReview == '1') {
  61. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '1');
  62. } else {
  63. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '0');
  64. }
  65. }
  66. Logger.debug('基础设置初始化');
  67. return _setting;
  68. }
  69. } catch (err) {
  70. Logger.error(err);
  71. }
  72. return null;
  73. }
  74. }