title: REST GET is returning invalid arguments in Future Builder
body: <p>I'm using a Rest API to call a GET method to fetch some Data. I'm doing this to load a profile to view inside my flutter body. I'm trying to assign these data to String variables inside the FutureBuilder method .
  In the future builder , the fetchUser() API call response should be returning, but the snapshot returns a null. and so when ever I try to run this, the screen is stuck in the CircularProgressIndicator.
  can someone help me to figure this out where I'm doing this wrong and how to solve it?</p>
  <p><em><strong>The body in flutter page</strong></em></p>
  <pre><code>final userProfileView = FutureBuilder&lt;UserFetch&gt;(
          future: CallApi().fetchUser(apiUrl),
          builder: (context, snapshot) {
            if(!snapshot.hasData)//(!snapshot.hasData)
              return Center(
                widthFactor: 120.0,
                heightFactor: 120.0,
                child: CircularProgressIndicator(),
              );
              // final userD = snapshot.data;
              _userName = snapshot.data.user.username.toString();
              _userEmail = snapshot.data.user.email;
              _userAddress = snapshot.data.user.address.toString();
              _userPassword = 'password';
              _userCountry = 'country';
              _userMobile = snapshot.data.user.mobile.toString();
              //checks if the response returns valid data
              return Container(
                child: Padding(
                  padding:
                      const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
                  child: SingleChildScrollView(
                    child: Column(
                      children: &lt;Widget&gt;[
                        userTitle,
                        SizedBox(height: 12.0),
                        userNameTitle,
                        userName,
                        SizedBox(height: 12.0),
                        userEmailTitle,
                        userEmail,
                        SizedBox(height: 12.0),
                        userPasswordTitle,
                        userPassword,
                        SizedBox(height: 12.0),
                        userAddressTitle,
                        userAddress,
                        SizedBox(height: 12.0),
                        userCountryTitle,
                        userCountry,
                        SizedBox(height: 12.0),
                        userPhoneTitle,
                        userPhone,
                        SizedBox(height: 24.0),
                        userLogoutBtn,
                      ],
                    ),
                  ),
                ),
              );
            // } else if (snapshot.hasError) {
            //   //checks if the response throws an error
            //   return Text(&quot;${snapshot.error}&quot;);
            // }
          });
  </code></pre>
  <p><em><strong>The Api Call</strong></em></p>
  <pre><code>Future&lt;UserFetch&gt; fetchUser(apiUrl) async {
      var fullUrl = _baseUrl + apiUrl;
      final response = await http.get(fullUrl, headers: _setHeaders());
  
      if (response.statusCode == 200) {
        // If the call to the server was successful (returns OK), parse the JSON.
        return UserFetch.fromJson(json.decode(response.body));
      } else {
        // If that call was not successful (response was unexpected), it throw an error.
        throw Exception('Failed to load User');
      }
    }
  </code></pre>
  <p><em><strong>The Response Model</strong></em></p>
  <pre><code>UserFetch userFetchFromJson(String str) =&gt; UserFetch.fromJson(json.decode(str));
  
  String userFetchToJson(UserFetch data) =&gt; json.encode(data.toJson());
  
  class UserFetch {
    UserFetch({
      this.success,
      this.user,
    });
  
    bool success;
    User user;
  
    factory UserFetch.fromJson(Map&lt;String, dynamic&gt; json) =&gt; UserFetch(
      success: json[&quot;success&quot;],
      user: User.fromJson(json[&quot;user&quot;]),
    );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
      &quot;success&quot;: success,
      &quot;user&quot;: user.toJson(),
    };
  }
  
  class User {
    User({
      this.email,
      this.address,
      this.imperial,
      this.mobile,
      this.petsInfo,
      this.role,
      this.subscribed,
      this.username,
    });
  
    String email;
    String address;
    bool imperial;
    String mobile;
    List&lt;PetsInfo&gt; petsInfo;
    String role;
    bool subscribed;
    String username;
  
    factory User.fromJson(Map&lt;String, dynamic&gt; json) =&gt; User(
      email: json[&quot;email&quot;],
      address: json[&quot;address&quot;],
      imperial: json[&quot;imperial&quot;],
      mobile: json[&quot;mobile&quot;],
      petsInfo: List&lt;PetsInfo&gt;.from(json[&quot;pets_info&quot;].map((x) =&gt; PetsInfo.fromJson(x))),
      role: json[&quot;role&quot;],
      subscribed: json[&quot;subscribed&quot;],
      username: json[&quot;username&quot;],
    );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
      &quot;email&quot;: email,
      &quot;address&quot;: address,
      &quot;imperial&quot;: imperial,
      &quot;mobile&quot;: mobile,
      &quot;pets_info&quot;: List&lt;dynamic&gt;.from(petsInfo.map((x) =&gt; x.toJson())),
      &quot;role&quot;: role,
      &quot;subscribed&quot;: subscribed,
      &quot;username&quot;: username,
    };
  }
  
  class PetsInfo {
    PetsInfo({
      this.id,
      this.name,
    });
  
    int id;
    String name;
  
    factory PetsInfo.fromJson(Map&lt;String, dynamic&gt; json) =&gt; PetsInfo(
      id: json[&quot;id&quot;],
      name: json[&quot;name&quot;],
    );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
      &quot;id&quot;: id,
      &quot;name&quot;: name,
    };
  }
  
  </code></pre>
  <p><em><strong>The Logs when user profile page called</strong></em></p>
  <pre><code>
  ════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
  'package:flutter/src/widgets/framework.dart': Failed assertion: line 273 pos 18: '_registry.containsKey(key)': is not true.
  ════════════════════════════════════════════════════════════════════════════════════════════════════
  
  ════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
  The following assertion was thrown while finalizing the widget tree:
  'package:flutter/src/widgets/framework.dart': Failed assertion: line 273 pos 18: '_registry.containsKey(key)': is not true.
  
  
  Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
  In either case, please report this assertion by filing a bug on GitHub:
    https://github.com/flutter/flutter/issues/new?template=BUG.md
  
  When the exception was thrown, this was the stack: 
  #2      GlobalKey._debugVerifyIllFatedPopulation.&lt;anonymous closure&gt; (package:flutter/src/widgets/framework.dart:273:18)
  #3      GlobalKey._debugVerifyIllFatedPopulation (package:flutter/src/widgets/framework.dart:298:6)
  #4      BuildOwner.finalizeTree.&lt;anonymous closure&gt; (package:flutter/src/widgets/framework.dart:2769:21)
  #5      BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2849:8)
  #6      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:915:18)
  
  </code></pre>