| | |
| | | |
| | | import 'package:shared_preferences/shared_preferences.dart'; |
| | | |
| | | import 'share_preference.dart'; |
| | | |
| | | class SettingUtil { |
| | | //设置推送 |
| | | static Future<bool> setPush(bool enable) async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | return await prefs.setBool("setting_push", enable); |
| | | await _setSetting("pushUnDisturb", enable); |
| | | return true; |
| | | } |
| | | |
| | | ///是否允许推送 |
| | | static Future<bool> isEnablePush() async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | bool? result = prefs.getBool("setting_push"); |
| | | result ??= true; |
| | | return result; |
| | | static Future<bool?> isEnablePush() async { |
| | | return await _getSetting("pushUnDisturb"); |
| | | } |
| | | |
| | | //设置推荐广告 |
| | | static Future<bool> setRecommendAd(bool enable) async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | return await prefs.setBool("setting_recommend_ad", enable); |
| | | await _setSetting("adRecommend", enable); |
| | | return true; |
| | | } |
| | | |
| | | ///是否允许推荐广告 |
| | | static Future<bool> isEnableRecommendAd() async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | bool? result = prefs.getBool("setting_recommend_ad"); |
| | | result ??= true; |
| | | return result; |
| | | static Future<bool?> isEnableRecommendAd() async { |
| | | return await _getSetting("adRecommend"); |
| | | } |
| | | |
| | | //设置推荐广告 |
| | | static Future<bool> setLocationSpan(int second) async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | return await prefs.setInt("setting_location_span", second); |
| | | //设置推荐内容 |
| | | static Future<bool> setRecommendContent(bool enable) async { |
| | | await _setSetting("contentRecommend", enable); |
| | | return true; |
| | | } |
| | | |
| | | ///是否允许推荐广告 |
| | | static Future<int> getLocationSpan() async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | int? result = prefs.getInt("setting_location_span"); |
| | | result ??= 30; |
| | | return result; |
| | | ///是否允许推荐内容 |
| | | static Future<bool?> isEnableRecommendContent() async { |
| | | return await _getSetting("contentRecommend"); |
| | | } |
| | | } |
| | | |
| | | static _setSetting(String key, bool value) async { |
| | | await dataMethodChannel |
| | | .invokeMethod("setSetting", {"key": key, "value": value}); |
| | | } |
| | | |
| | | static Future<bool?> _getSetting(String key) async { |
| | | return await dataMethodChannel.invokeMethod("getSetting", key); |
| | | } |
| | | } |