1

So this is my first time publishing a Flutter app to the Google Play Store. I wanted to create something simple so I could learn the entire process. So I created a simple Trivia App.

When I run the app from my phone or emulator (Android or iPhone) the free API that I'm using here loads the categories without any issues.

What the app should look like

The issue I'm having is when I publish the app to the Play Store, the API doesn't load and I don't even get an error message. Just a blank screen.

App when published to play store

Here is the API service call in my app:

 static Future<List<Category>> fetchCategories() async {
    const url = "https://opentdb.com/api_category.php";
    var response;
    try {
      response = await http.get(url);
      if (response.statusCode == 200) {
        var jsonString = response.body;
        final Map<String, dynamic> responseData = json.decode(jsonString);
        var list = responseData['trivia_categories'] as List;
        var _items = list.map((i) => Category.fromJson(i)).toList();
        return _items;
      } else {
        return null;
      }
    } on Exception {
      throw response.statusCode;
    }
  }

And this is the code in the controller that calls the API's method.

 void fetchCategories() async {
    // flag as loading.
    isLoading(true);
    try {
      //get categories from API server
      var categories = await ApiServices.fetchCategories();
      if (categories != null) {
        categories.forEach((Category categoryItem) async {
          // adjust data accordingly
          categoryItem.totalQuestions =
              await fetchCategoryCount(categoryItem.id);
          if (userDataController.data.read(categoryItem.id.toString()) !=
              null) {
            // get a list of answered questions from the device and count them
            List<dynamic> correctAnswers =
                userDataController.data.read(categoryItem.id.toString());
            categoryItem.correctAnswers = correctAnswers.length;
          } else {
            categoryItem.correctAnswers = 0;
          }
          categoryTiles.add(categoryItem);
        });
      }
    } on Exception catch (e) {
      throw new Exception("An error occured fetching the data");
    } finally {
      isLoading(false);
    }
  }

Has anyone else ran into this issue?

Robert
  • 159
  • 2
  • 12

0 Answers0