Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/src/helpers/cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class CacheManager {
static Future getJson({required String key}) async {
dynamic cache;
static Future<Map<String, dynamic>?> getJson({required String key}) async {
String? cache;
try {
final sharedPreferences = await SharedPreferences.getInstance();
cache = sharedPreferences.getString(key);
} catch (e) {
debugPrint('Cache URL had a change => $e');
}
dynamic jsonMapCache;
Map<String, dynamic>? jsonMapCache;
if (cache != null) {
jsonMapCache = jsonDecode(cache) as Map<dynamic, dynamic>;
jsonMapCache = jsonDecode(cache) as Map<String, dynamic>;
}
return jsonMapCache;
}
Expand All @@ -25,12 +25,11 @@ class CacheManager {
.whenComplete(() => (takeAction as void Function()?)?.call());
}

static Future setJson({
static Future<void> setJson({
required String key,
required Map<dynamic, dynamic> value,
required Map<String, dynamic> value,
}) async {
final sharedPreferences = await SharedPreferences.getInstance();
var jsonMap = value;
await sharedPreferences.setString(key, jsonEncode(jsonMap));
await sharedPreferences.setString(key, jsonEncode(value));
}
}
3 changes: 2 additions & 1 deletion lib/src/helpers/link_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class LinkAnalyzer {
Metadata? info_;

try {
final infoJson = await CacheManager.getJson(key: url);
final Map<String, dynamic>? infoJson =
await CacheManager.getJson(key: url);
if (infoJson != null) {
info_ = Metadata.fromJson(infoJson);
var isEmpty_ = info_.title == null || info_.title == 'null';
Expand Down