bookmarksParser method
Implementation
@override
List<Bookmark> bookmarksParser(String bookmarkPath) {
List<Bookmark> _deeper(
Map<String, dynamic> json,
String folder,
List<Bookmark> bookmarksList,
) {
for (var node in json.keys) {
if (node == 'children') {
for (var child in json[node]) {
if (child['type'] == 'url') {
bookmarksList.add(Bookmark(
folder: folder,
url: child['url'],
name: child['name'],
date: dateParse(child['date_added']),
));
} else if (child['type'] == 'folder') {
bookmarksList =
_deeper(child, join(folder, child['name']), bookmarksList);
}
}
break;
} else {
bookmarksList = _deeper(json[node], folder, bookmarksList);
}
}
return bookmarksList;
}
Map<String, dynamic> bm = jsonDecode(File(bookmarkPath).readAsStringSync());
List<Bookmark> bookmarksList = [];
Map<String, dynamic> roots = bm['roots'];
for (var root in roots.keys) {
if (roots[root] is Map) {
bookmarksList = _deeper(roots[root], root, bookmarksList);
}
}
return bookmarksList;
}