基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base_setting_model.dart 2.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'dart:io';
  2. import 'package:zhiying_comm/util/net_util.dart';
  3. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  4. import 'package:zhiying_comm/zhiying_comm.dart';
  5. class BaseSettingModel {
  6. String fileProvider;
  7. String fileBucketHost;
  8. String fileBucketHostProtocol;
  9. String isIosReview;
  10. Map<String, dynamic> tab;
  11. static BaseSettingModel _setting;
  12. static BaseSettingModel get setting {
  13. if (_setting == null) {
  14. Logger.error('暂未初始化');
  15. }
  16. return _setting;
  17. }
  18. BaseSettingModel(
  19. {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() async {
  37. Map result =
  38. await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET);
  39. try {
  40. var data = result['data'];
  41. _setting = BaseSettingModel.fromJson(Map<String, dynamic>.from(data));
  42. if(Platform.isIOS) {
  43. if (null != _setting && _setting.isIosReview == '1') {
  44. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '1');
  45. } else {
  46. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '0');
  47. }
  48. }
  49. Logger.debug('基础设置初始化');
  50. return _setting;
  51. } catch (err) {
  52. Logger.error(err);
  53. }
  54. return null;
  55. }
  56. }