Comments (5)
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
from lite_rolling_switch.
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.
from lite_rolling_switch.
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!
from lite_rolling_switch.
Related Issues (13)
- resizing of widget. HOT 5
- Intento redibujar el widget y no me lo permite HOT 1
- null-safety HOT 3
- Active icon is different size than inactive icon HOT 1
- Too big HOT 1
- on change function is being called on load HOT 6
- abandoned package? HOT 1
- Intl 0.18.0 HOT 3
- Disable animation without change
- License HOT 2
- Size of Icon can't be changed HOT 5
- [Request] Turn off rolling animation HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lite_rolling_switch.