How to handle setState in a function ?
I have 2 functions where the user press a button and i save and load the state of that button whenever i need it ,also i store it in sharedPreference.
I want to move that code :
Future<void> _loadPrivacyPolicyAcceptance() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
_acceptedPrivacyPolicy = prefs.getBool('acceptedPrivacyPolicy') ?? false;
});
}
Future<void> _savePrivacyPolicyAcceptance(bool accepted) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool('acceptedPrivacyPolicy', accepted);
}
In a new file where i use only functions and not widgets ,but i can’t use setState without a widget.
How i can handle that behaviour ?