I have a CupertinoSwitch which works great for sliding but I would also like it to change it when I tap on it.
I tried wrapping it in an inkwell and a gesture detector and setting the value like this:
GestureDetector(
child: CupertinoSwitch(
value: notificationsAllowed,
activeColor: Colors.orange,
onChanged: (notificationsSelection) {
userProfile
.userNotificationsPermitted =
notificationsSelection;
},
),
onTap: (){
setState(() {
print ('tapped');
notificationsAllowed = true;
});
},
),
But what I have found is that the inkwell is not registering the tap, I assume because it is not gaining focus.
I tried both inkwell and gesture but I am not sure why it is not registering the tap event.
Thanks
GestureDetector(
child: Container(
width: 42.0,
height: 24.0,
color: Colors.white,
padding: EdgeInsets.symmetric(21.0),
child: CupertinoSwitch(
value: notificationsAllowed,
activeColor: Colors.orange,
onChanged: (notificationsSelection) {
userProfile
.userNotificationsPermitted =
notificationsSelection;
},
),
),
onTap: (){
setState(() {
print ('tapped');
notificationsAllowed = true;
});
},
),
but CupertinoSwitch onChanged method not work!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With