Giter VIP home page Giter VIP logo

Comments (4)

cgustav avatar cgustav commented on June 26, 2024

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.

hulan0523 avatar hulan0523 commented on June 26, 2024

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.

cgustav avatar cgustav commented on June 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.