There are many country in the world, Here we will try to display all country info using API with Flutter. API calling is very useful tool for all Mobile applications.

You can Download Source Code via Github.

API call

 List<CountryResponse> _postList =new List<CountryResponse>();
  Future<List<CountryResponse>> countryList() async {
    String url = "all";

    http.Response response = await http.get(
      _endpoint + url,
    );
    if (response.statusCode == 200) {
      // If the call to the server was successful, parse the JSON
      List<dynamic> values = new List<dynamic>();
      values = json.decode(response.body);
      if (values.length > 0) {
        for (int i = 0; i < values.length; i++) {
          if (values[i] != null) {
            Map<String, dynamic> map = values[i];
            debugPrint('Name-------${map['name']}');
            _postList .add(CountryResponse.fromMap(map));
          }
        }
      }
      return _postList;
    }
  }

List tiles Widgets

 Widget listTile(CountryResponse chatData, int index, int length) {
      return Container(
        padding: EdgeInsets.all(5),
        child: Row(
          children: [
            Container(
              margin: EdgeInsets.only(right: 16),
              height: 48,
              width: 48,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  image: DecorationImage(
                      image: chatData.name != null && chatData.flag.isNotEmpty
                          ? NetworkImage('https://flagcdn.com/w320/' +
                              chatData.alpha2Code.toLowerCase() +
                              '.png')
                          : AssetImage(ImageUtils.noProfileImage),
                      fit: BoxFit.cover)),
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    chatData.name,
                    style: chatNameStyle,
                  ),
                  Text(
                    chatData.capital,
                    style: chatEmailStyle,
                  )
                ],
              ),
            ),
          ],
        ),
      );
    }

You can Download Source Code via Github.