deleteProfile function
- BuildContext context
When in editing mode, this function is called to delete the active user.
It removes the PersonalDataProvider.activeUser element of the list PersonalDataProvider.profilesList, and updates the PersonalDataProvider.profileCounter. Then saves the profiles list in shared preferences and goes back to the home page
The only argument is context to access the providers
Implementation
void deleteProfile(BuildContext context) async {
final personalDataProvider = Provider.of<PersonalDataProvider>(context, listen: false);
final buttonsProvider = Provider.of<ButtonsProvider>(context, listen: false);
personalDataProvider.profilesList.removeAt(personalDataProvider.activeUser ?? 0);
personalDataProvider.profileCounter--;
buttonsProvider.setIsUserSelected(false);
personalDataProvider.setActiveUser(null); //Para que no se cuelgue testParametersScreen al volver
await personalDataProvider.saveProfiles();
Navigator.pushNamed(context, '/');
personalDataProvider.resetTempUser();
}