1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Is there a way to count the number of specific files on a server with Flutter/Dart?

Discussão em 'Mobile' iniciado por Stack, Setembro 27, 2024 às 21:23.

  1. Stack

    Stack Membro Participativo

    This seems like a trivial question - but I have failed miserably to find a simple way of counting the number of files of a particular ilk on my server with Flutter/Dart. Please don't suggest Backendless as that appears as if it can do the trick at tremendous cost with something that is still under development.

    I have tried to return a future and looking at it much later and tried to modify a global and look at in a screen much later - but have failed. Knowing what I know now, I would have included in the master file (previously read in as jsonMap).

    Here is my miserable attempt to see how many of the 10 json files are present. This includes two tries - one to return a future index and the other to increment a global.

    As my title suggests - Is there a simple way of seeing how many files of a certain ilk are present on the server?

    Future _checkUrl(String url) async {
    http.Response urlResponse = await http.get(Uri.parse(url));
    if (urlResponse.statusCode == 200) {
    return true;
    } else {
    return false;
    }
    }

    Future<int> getMaxEngagementIndex(int currentSermonIndex) async {
    // maxEngagementTextIndex is range -1 to 9 (-1 should never happen - no engagement files)
    String? engagementFileName;
    maxEngagementIndexShadow = 0;
    int index = 0;
    for (int i = 0; i < 10; i++) {
    engagementFileName =
    pick(jsonMap, currentSermonIndex, 'engagements', i, 'text_a')
    .asStringOrNull();
    if (engagementFileName == null || engagementFileName == '') {
    engagementFileName = '2024-03-170Ia.json';
    }
    _checkUrl(
    'MY_SERVER')
    .then((filePresent) {
    if (filePresent) {
    index++;
    maxEngagementIndexShadow++;
    }
    });
    }
    return index;
    }

    Continue reading...

Compartilhe esta Página