-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
003750d
commit 60101dd
Showing
4 changed files
with
896 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class FavouriteScreenProvider with ChangeNotifier { | ||
bool _drawingBoard = false; | ||
bool get drawingBoard => _drawingBoard; | ||
|
||
List<int> _selectedItemList = []; | ||
|
||
List<int> get selectedItemList => _selectedItemList; | ||
|
||
FavouriteScreenProvider() { | ||
loadFromPrefs(); | ||
} | ||
|
||
void setDrawingBoard() { | ||
_drawingBoard = !_drawingBoard; | ||
notifyListeners(); | ||
saveToPrefs(); | ||
} | ||
|
||
void setList(int item) { | ||
_selectedItemList.add(item); | ||
notifyListeners(); | ||
saveToPrefs(); | ||
} | ||
|
||
void removeList(int item) { | ||
_selectedItemList.remove(item); | ||
notifyListeners(); | ||
saveToPrefs(); | ||
} | ||
|
||
Future<void> loadFromPrefs() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
_drawingBoard = prefs.getBool('drawingBoard') ?? false; | ||
_selectedItemList = prefs | ||
.getStringList('selectedItemList') | ||
?.map((e) => int.parse(e)) | ||
.toList() ?? | ||
[]; | ||
notifyListeners(); | ||
} | ||
|
||
Future<void> saveToPrefs() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
await prefs.setBool('drawingBoard', _drawingBoard); | ||
await prefs.setStringList('selectedItemList', | ||
_selectedItemList.map((e) => e.toString()).toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.