acceptCredentialTerms function
- BuildContext context, {
- required bool hasAcceptedMarketingOutreach,
Record that the given user has accepted the credential terms.
The user will be added to the list of accepted credential terms users.
Implementation
Future<bool> acceptCredentialTerms(
BuildContext context, {
required bool hasAcceptedMarketingOutreach,
}) async {
final container = ProviderScope.containerOf(context);
final user = container.read(currentUserProvider).valueOrNull?.id;
final api = await container.read(energyManagementV3ApiProvider.future);
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool('hasAcceptedMarketingOutreach', true);
assert(user != null);
if (!context.mounted) return false;
final hasAddedUser = await addStringToPrefList(
context,
provider: acceptedCredentialTermsUsersProvider,
value: user!,
);
if (hasAddedUser) {
final body = HomeownerUpdateV3Body(
hasAcceptedTC: true,
hasAcceptedMarketingOutreach: hasAcceptedMarketingOutreach,
);
final response = await api.kemApiV3HomeownerMePut(body: body);
assertSuccessfulResponse(response);
}
return hasAddedUser;
}