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

[Flutter] Flutter - Load assets for tests

Discussão em 'Mobile' iniciado por Stack, Outubro 31, 2024 às 12:52.

  1. Stack

    Stack Membro Participativo

    Not sure if it's a limitation or something, but below code does not load anything. I have some data driven behaviour that I'd like to test isolated.

    class Loader

    import 'dart:async';
    import 'package:flutter/services.dart' show rootBundle;

    class Loader {
    Future<String> load() async{
    return await rootBundle.loadString('assets/json/sketch.json');
    }
    }


    The test

    testWidgets('Should parse load sketch.json', (WidgetTester tester) async {
    var loaderFuture = new Loader();

    Future<String> resultFuture = loaderFuture.load();

    resultFuture.then((value) => print(value))
    .catchError((error) => print(error));

    while(true){};
    });


    Future does not return neither success nor error and hangs forever. I know the while(true) locking up the test, but for now I just wanted to see sketch.json printed

    Asset location

    [​IMG]

    Continue reading...

Compartilhe esta Página