Below is my ViewModel class :
class SignInViewModel extends ChangeNotifier {
var isRememberMeChecked = false;
final TextEditingController emailC = TextEditingController();
final TextEditingController passwordC = TextEditingController();
Future<bool> signIn({
required String email,
required String password,
}) async {
/// Implement Api Call Here
return true;
}
}
You can see the class is extending ChangeNotifier & Please not the variable named isRememberMeChecked which is by default 'false'.
Now, In my Widget class, which is StateFulWidget, I am trying to change the value of CheckBox as below:
child: Checkbox(
fillColor: theme.checkboxTheme.fillColor,
value: widget.viewModel.isRememberMeChecked,
onChanged: (bool? value) {
widget.viewModel.isRememberMeChecked=value!;
},
),
You can notice this line:
widget.viewModel.isRememberMeChecked=value!;
EDIT:
I have also tried it with set as below:
widget.viewModel.setRememberMe = value
In ViewModel class :
set setRememberMe(bool value) {
isRememberMeChecked = value;
notifyListeners();
}
But with this also Checkbox UI not getting checked to unchecked. Means the Checkbox UI is not reflecting for true or false values.
What might be the issue?
Aucun commentaire:
Enregistrer un commentaire