Provider file
class TermsOfServiceProvider extends ChangeNotifier {
bool _termsOfService = false;
bool get termsOfService => _termsOfService;
void termsOfServiceUpdated(bool value) {
_termsOfService = value;
notifyListeners();
}
}
Above is the provider I am using.
CheckoutButton(
onPressed:
context.watch<TermsOfServiceProvider>().termsOfService
? () {
orderAddressBloc.handleFormSubmit(
addressFormValues!.value,
customerInfoFormValues!.value,
useAsBilling: useAsBillingValue.value,
optedIn: optIn.value,
termsAndConditions: termsConditions.value,
);
}
: null,
blocLoadingIndicator: orderAddressBloc.loadingIndicator,
),
Above is where I am using the value.
But when I'm popping away from this page and returning the value of termsOfService
when coming back is not changing.
I am using a checkbox for handling the data validation so when it is true it is activating a button to be clicked and false the button is inactive.
But when I am clicking for it to be true and navigating away and coming back the checkbox is not ticked but the value is true
, setting the button to active when it shouldn't be.
child: CheckboxListTile(
value: checkedValue,
onChanged: (bool? newValue) {
context
.read<TermsOfServiceProvider>()
.termsOfServiceUpdated(newValue!);
setState(() {
checkedValue = newValue;
});
},
Above is the checkbox code.
Aucun commentaire:
Enregistrer un commentaire