import 'dart:convert';
|
|
import 'package:flutter/cupertino.dart';
|
import '../../api/config_api.dart';
|
import '../api/http.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
class ConfigUtil {
|
///保存配置信息
|
static void saveConfig(Map<String, dynamic> map) async {
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
await prefs.setString("config_value", jsonEncode(map));
|
}
|
|
static Future<String?> getConfig(BuildContext context, String key) async {
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
String? result = prefs.getString("config_value");
|
if (result != null) {
|
Map<String, dynamic> map = jsonDecode(result);
|
return map[key];
|
} else {
|
//重新请求
|
ConfigApiUtil.getConfig(context).then((value) {
|
if (value == null) {
|
return;
|
}
|
if (value["code"] == 0) {
|
saveConfig(value["data"]);
|
}
|
});
|
}
|
return null;
|
}
|
}
|
|
class ConfigKey {
|
//客服
|
static const String kefu = "kefu";
|
|
//教程
|
static const String course = "course";
|
|
//注销
|
static const String unRegister = "unRegister";
|
|
//隐私投诉
|
static const String privacyComplain = "privacyComplain";
|
|
//会员链接
|
static const String vipLink = "vipLink";
|
|
//三方SDK链接
|
static const String sdkList = "sdkList";
|
}
|
|
enum SharePlatform { wx, wxcircle, qq, qqzone, sina }
|