I am building an auth screen where i am using isLogin
boolean... I created a method to change the value of isLogin but it requires ctrl s or use SetState()
to change the value and update UI...
here is the Provider class code
bool _isLogin = true;
bool get isLogin => _isLogin;
changeAuth(value) {
_isLogin = value;
notifyListeners();
}
here I am calling method
TextButton(
onPressed: () {
auth.changeAuth(
auth.isLogin == true ? false : true);
},
child: Text(
auth.isLogin
? "Register a new account"
: "Login instead",
style: const TextStyle(
decoration: TextDecoration.underline,
color: Colors.blue),
))
CodePudding user response:
If auth
is Provider
TextButton(
onPressed: () {
context.read<ProviderClassName>().changeAuth(
context.read<ProviderClassName>().isLogin == true ? false : true);
},
child: Text(
context.watch<ProviderClassName>().isLogin
? "Register a new account"
: "Login instead",
style: const TextStyle(
decoration: TextDecoration.underline,
color: Colors.blue),
))