Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update the value programatically #17

Open
MySelfMukund opened this issue Jul 7, 2021 · 4 comments
Open

How to update the value programatically #17

MySelfMukund opened this issue Jul 7, 2021 · 4 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@MySelfMukund
Copy link

HI,
Can you please suggest how to update the value programatically.

@cgustav
Copy link
Owner

cgustav commented Sep 4, 2022

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

@cgustav cgustav added the help wanted Extra attention is needed label Sep 4, 2022
@cgustav cgustav self-assigned this Sep 4, 2022
@hulan0523
Copy link

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.

@cgustav
Copy link
Owner

cgustav commented Jan 12, 2023

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!

@Adbhutashra26
Copy link

How to update the value with Realtime Firebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants