title: Flutter how can i check api response is error or not
body: <p>I am simply using an api for login. Its working fine I need to just print if its showing an error in response</p>
  <p>My code</p>
  <pre><code>  _trySubmit() async {
      final isValid = _formKey.currentState.validate();
      FocusScope.of(context).unfocus();
  
      if (isValid) {
        _formKey.currentState.save();
  
        print(_userName.trim());
        print(_userPassword.trim());
  
        var map = new Map&lt;String, dynamic&gt;();
  
        map['username'] = _userName.trim();
        map['password'] = _userPassword.trim();
        
        Map&lt;String,String&gt; headers = {'Content-Type':'application/json'};
        final msg = jsonEncode({&quot;username&quot;:_userName.trim(),&quot;password&quot;:_userPassword.trim()});
  
        http.Response res = await http.post(
          'http://api.igiinsurance.com.pk:8888/insurance_Igitakaful/mobile/login.php',
          headers: headers,
          body: msg,
        );
        var data = json.decode(res.body.toString());
        print(data);
        print(data['Cnic']);
        if(data['Cnic'].length &gt; 2) {
          final storage = new FlutterSecureStorage();
          await storage.write(key: 'Cnic', value: data['Cnic']);
  
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) =&gt; HomePage()),
          );
        }
        else{
          print('error');
  
        }
  
      }
  </code></pre>
  <p>You can see I am using if else condition like when data['Cnic'] have length greater then 2 it will change the page but I need to check if its showing error in response its just print you have error or something</p>