updateServiceAgreementApi function
- required BuildContext context,
- required int deviceId,
- required ServiceAgreementFormData data,
Update a device's service agreement details
Implementation
Future<void> updateServiceAgreementApi({
required BuildContext context,
required int deviceId,
required ServiceAgreementFormData data,
}) async {
final parentContext = context
.getElementForInheritedWidgetOfExactType<UncontrolledProviderScope>();
// Use the parent context to allow for refreshing a device even if the
// original context is disposed
if (parentContext != null) {
context = parentContext;
}
final api = await context.read(energyManagementV3ApiProvider.future);
final response = await api.kemApiV3DevicesIdServiceagreementPut(
id: deviceId,
body: ServiceAgreementUpdateV3Body(
hasServiceAgreement: data.hasServiceAgreement,
beginDate: data.beginDate,
term: serviceAgreementTermToDTO(data.term),
termMonths: data.termMonths,
termDays: data.termDays,
),
);
assertSuccessfulResponse(response);
if (!context.mounted) return;
final refreshDetails = context.read(fullRefreshGeneratorDetailsProvider);
await refreshDetails(context, deviceId);
}