Open MySelfMukund opened 3 years ago
Hi, im really sorry for the late response :(
In case you still want to continue with this case, what value do you mean exactly? thank you for your interest in the project
I got a similar question. I want to set the value by using setState() when the notification API returns 200, but the widget only seems to change when onChanged happens.
LiteRollingSwitch(
//initial value
value: bSubscribe,
width: ScreenUtil().setWidth(250),
textOn: t.ON,
textOff: t.OFF,
colorOn: AppColors.themeBlue,
colorOff: AppColors.darkGrey,
iconOn: Icons.notifications,
iconOff: Icons.notifications_off,
textSize: ScreenUtil().setSp(40),
textOnColor: Colors.white,
onChanged: (bool state) {
_subscriptionAPI(!bSubscribe);
},
onTap: () {},
onDoubleTap: () {},
onSwipe: () {},
)
if (response.statusCode == 200) {
await prefs.setBool(widget.currentDeviceName, doSubscribe);
setState(() {
bSubscribe = doSubscribe;
});
}
Also, I wonder if I should add _subscriptionAPI(!bSubscribe) to all events or just onChanged is enough.
Hi @hulan0523, I highly recommend using the state value that you are receiving through the component callback onChanged, as this is the current value that you want to change. This way, you can ensure that your code sends the 'real' value of the component state to be updated (i.e., the value that should be sent to your API). Additionally, it is considered best practice to receive the new state directly from the API once the value has been updated, if this is an approachable option from your API's response.
LiteRollingSwitch(
//initial value
value: bSubscribe,
width: ScreenUtil().setWidth(250),
textOn: t.ON,
textOff: t.OFF,
colorOn: AppColors.themeBlue,
colorOff: AppColors.darkGrey,
iconOn: Icons.notifications,
iconOff: Icons.notifications_off,
textSize: ScreenUtil().setSp(40),
textOnColor: Colors.white,
onChanged: (bool state) {
_subscriptionAPI(state);
},
onTap: () {},
onDoubleTap: () {},
onSwipe: () {},
)
I hope this could be of help
Cheers!
How to update the value with Realtime Firebase
in case on switch tap i want to confirmation and according to dialog input if yes then only i want to change the value of switch for this type case this switch is not usefull. in future you can update this to update value programaticaly.
HI, Can you please suggest how to update the value programatically.