title: How to sort data from api?
body: <p>There are two dropdown button with the list of countries and types of sport. If on them somsething is chosen it is need to show listTile with the leagues on it is chosen to the country and/or sport and if on them nothing is chosen - show all leagues. </p>
  
  <p>But I get:</p>
  
  <blockquote>
    <p>Dart Error: Unhandled exception:
     setState () called after dispose (): _SportLigPageState # b5830 (lifecycle state: defunct, not mounted)
     This is what happens if you see the widget tree (e.g.). This error can occur when a call is made. Dispose () callback. It is necessary to ensure that the object is still in the tree.
    This can be a memory card if it’s not. To avoid memory leaks, consider dispose (). </p>
  </blockquote>
  
  <p>Api with leagues: <a href="https://www.thesportsdb.com/api/v1/json/1/all_leagues.php" rel="nofollow noreferrer">https://www.thesportsdb.com/api/v1/json/1/all_leagues.php</a>:</p>
  
  <pre><code>class LigList extends StatefulWidget {
    @override
    _LigListState createState() =&gt; _LigListState();
  }
  
  class _LigListState extends State&lt;LigList&gt; {
    String sport;
    String country;
    List data;
    Future&lt;String&gt; getJsonData() async {
      http.Response response;
      if (sport != null) {
        if (country != null) response  = await http
            .get(Uri.encodeFull('https://www.thesportsdb.com/api/v1/json/1/all_leagues.php?c=$sport&amp;s=$country'), headers: {"Accept": "application/json"});
        else  response  = await http
            .get(Uri.encodeFull('https://www.thesportsdb.com/api/v1/json/1/all_leagues.php?c=$sport'), headers: {"Accept": "application/json"});}
      else if (country == null){ response  = await http
          .get(Uri.encodeFull('https://www.thesportsdb.com/api/v1/json/1/all_leagues.php'), headers: {"Accept": "application/json"});}
      else  response  = await http
            .get(Uri.encodeFull('https://www.thesportsdb.com/api/v1/json/1/all_leagues.php?c=$country'), headers: {"Accept": "application/json"});
  
  
        var convertDatatoJson = json.decode(response.body);
        data = convertDatatoJson['leagues'];
      return "Success";
    }
  
    static const menuItems = countriesList;
    final List&lt;DropdownMenuItem&lt;String&gt;&gt; _dropDownItems = menuItems
        .map((String CountruValue) =&gt;
        DropdownMenuItem&lt;String&gt;(
          value: CountruValue,
          child: Text(CountruValue),
        ),
    ).toList();
  
    @override
    Widget build(BuildContext context) {
      return Container(
        child: Center(
          child: Column(children: &lt;Widget&gt;[
            FutureBuilder(
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  return DropdownButton(
                    value: country,
                    hint: Text("Choose a countre league of which you want to find"),
                    items:  _dropDownItems,
                    onChanged: (value) {
                      country = value;
                      print(country);
                      setState(() {});
                    },
                  );}),
            SizedBox(width: 5),
            FutureBuilder(
                future: _getSports(),
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  return snapshot.hasData
                      ? DropdownButton(
                    value: sport,
                    hint: Text("Choose a sport league of which you want to find"),
                    items: snapshot.data,
                    onChanged: (value) {
                      sport = value;
                      print(sport);
                      setState(() {});
                    },
                  )
                      : Padding(
                      padding: EdgeInsets.symmetric(vertical: 20),
                      child: CircularProgressIndicator());
                }),
            Flexible(
                child:FutureBuilder(
                    future: getJsonData(),
                    builder: (BuildContext context, AsyncSnapshot snapshot) {
                      return ListView.separated(
                          itemCount: data == null ? 0 : data.length,
                          itemBuilder: (BuildContext context, int i) {
                            return Container(
                                child: Center(
                                    child: Column(
                                        crossAxisAlignment: CrossAxisAlignment
                                            .stretch,
                                        children: &lt;Widget&gt;[
                                          ListTile(
                                            title: Text(data[i]['strLeague']),
                                            subtitle: Text(
                                                data[i]['strSport']),
                                            onTap: () {
                                              Navigator.push(
                                                  context,
                                                  new MaterialPageRoute(
                                                      builder: (
                                                          BuildContext context) =&gt;
                                                      new ComandListScreen()
                                                    // (data[i])
                                                  ));
                                            },
                                          ),
                                        ]
                                    )
                                )
                            );
                          });
                    }))
          ]),
        ),
      );
    }
  }
  </code></pre>
  
  <p>Any assistance is very much appreciated.</p>