Ad

I Am Trying To Get TimeZones From An API In Flutter But Due To Some Reason Its Not Returning All TimeZones

- 1 answer

I am new to the flutter framework. I am trying to get TimeZones from an API in flutter but due to some reason, it's not returning all timeZones. URL from which I am trying to get a response is: https://www.timeapi.io/api/TimeZone/AvailableTimeZones

Here is my code :

import 'package:http/http.dart';
import 'dart:convert';

class WorldClock {
  late String location;
  late String time;
  late String flag;
  late String url;
  late bool isDayTime = false;

  WorldClock({required this.location, required this.flag, required this.url});

  Future<void> getLocations() async {
    try {
      Response response = await get(
          Uri.parse('https://www.timeapi.io/api/TimeZone/AvailableTimeZones'));
      print(response.body);
    } catch (e) {
      print('failed to load locations');
    }
  }

The output I am getting is :

["Africa/Abidjan","Africa/Accra","Africa/Addis_Ababa","Africa/Algiers","Africa/Asmara","Africa/Asmera","Africa/Bamako","Africa/Bangui","Africa/Banjul","Africa/Bissau","Africa/Blantyre","Africa/Brazzaville","Africa/Bujumbura","Africa/Cairo","Africa/Casablanca","Africa/Ceuta","Africa/Conakry","Africa/Dakar","Africa/Dar_es_Salaam","Africa/Djibouti","Africa/Douala","Africa/El_Aaiun","Africa/Freetown","Africa/Gaborone","Africa/Harare","Africa/Johannesburg","Africa/Juba","Africa/Kampala","Africa/Khartoum","Africa/Kigali","Africa/Kinshasa","Africa/Lagos","Africa/Libreville","Africa/Lome","Africa/Luanda","Africa/Lubumbashi","Africa/Lusaka","Africa/Malabo","Africa/Maputo","Africa/Maseru","Africa/Mbabane","Africa/Mogadishu","Africa/Monrovia","Africa/Nairobi","Africa/Ndjamena","Africa/Niamey","Africa/Nouakchott","Africa/Ouagadougou","Africa/Porto-Novo","Africa/Sao_Tome","Africa/Timbuktu","Africa/Tripoli","Africa/Tunis","Africa/Windhoek","America/Adak","America/Anchorage","America/Anguilla","America/Antigua","America/Ar

From the output, you can clearly see after Ameria/Ar, it's breaking and not storing it.
Any possible fix?

Ad

Answer

Every ide has a max console log limit, you can change these limits.

If you are using IntelliJ or Android Studio IDE follow below link; https://stackoverflow.com/a/66744625/13109852

or using VSCode follow below link; https://stackoverflow.com/a/63013785/13109852

Ad
source: stackoverflow.com
Ad