Home > Back-end >  Loop do while dart flutter
Loop do while dart flutter

Time:02-01

i want to increase value of double _borderwidth and double _loginButtonVisibility every time when this TextFormField is onChanged, but only until this every value will equals 0.5

 TextFormField(
       onChanged: (firFieldChange) {
         setState(() {
           do {
             _borderwidth = 0.125   _borderwidth;
          } while (_borderwidth == 0.5);
           do {
             _loginButtonVisibility =
               0.125   _loginButtonVisibility;
           } while (_loginButtonVisibility == 0.5);
         });
       },),

CodePudding user response:

You don't want a loop, you want a simple if:

setState(() {
      if(_borderwidth < 0.5) {
         _borderwidth = 0.125   _borderwidth;
      } 
       if(_loginButtonVisibility == 0.5) {
         _loginButtonVisibility = 0.125   _loginButtonVisibility;
       }
     });

Please note that you still need checks for what happens if one of the variables is not a multiple of 0.125. What if it is 0.4 and then ends up being 0.525?

  •  Tags:  
  • Related