简体   繁体   中英

I am having problem with if statement in dart

child: RaisedButton(
    onPressed: () {
      if (_formKey.currentState.validate()) {
        double angle = double.parse(a.text);
​
        print(angle);
        if (v.text != null) {
          double velocity = double.parse(v.text);
          print(velocity);
        } else if (h.text != null) {
          double height = double.parse(h.text);
          print(height);
          print(angle);
        } else if (t.text != null) {
          double time = double.parse(t.text);
          print(time);
          print(angle);
        }
      }
    },

In the following code when I keep v.text empty it still reads the if statement and not jump to else if part while i validate the form. i don't know why it is doing this please help me out

Instead of v.text != null

do v.text.isNotEmpty

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM