'how can i save data with SharedPreferences with provider
I am using Provider to create a bookmark page and it works correctly but I need to sore the data with SharedPreferences so I can find it again when I rebuild the app here is my provider method for storing the data
void addItemToBookmark(
String id, String title, int counts, int pageNum) async {
final _preferances = await .getInstance();
// final loadId = _preferances.getString('id');
// print(loadId);
final savedId = await _preferances.setString('id', id);
if (_bookmarkeTitle.containsKey(id)) {
_bookmarkeTitle.update(
id,
(existingtitle) => DataModel(
id: id,
title: title,
counts: counts,
pageNum: pageNum,
),
);
_bookmarkeTitle.remove(id);
_preferances.remove('id');
} else {
_bookmarkeTitle.putIfAbsent(
id,
() => DataModel(
id: id,
title: title,
counts: counts,
pageNum: pageNum,
),
);
// print(savedId);
}
notifyListeners();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
