Flutter app can't load Json file while being run with flutter_driver

1,148

There is an outstanding issue for this on Flutter GitHub. It appears there is an issue with the VM and an isolate in Flutter Driver.

See this comment https://github.com/flutter/flutter/issues/30641#issuecomment-524868136 it has a link to a fork of Flutter with an example of a test (here https://github.com/vishna/flutter/commit/2f858fc334fc2f43b92c318d02bdbf1ad0984033) that has solved this sort of issue for me in the passed

Also, maybe worth sharing your source code so that people can run/debug etc.

Share:
1,148
patreu22
Author by

patreu22

Student of computer science. Interested in iOS, Web Development, Java, Python coding. Still working hard on my Backend developing skills for web applications.

Updated on December 14, 2022

Comments

  • patreu22
    patreu22 over 1 year

    I'm trying to setup my Flutter app to automate screenshots using flutter_driver and integration tests, but the app is stuck at the point where it should await a future for a *.json file.
    Does anybody know how to fix that?

    Steps to Reproduce

    1. Setup an app that needs to read a Json File (I used this method: String myJson = await rootBundle.loadString('my_resources/myjson.json');
    2. Set up a flutter_driver test:

    App.dart:

    import 'package:flutter_driver/driver_extension.dart';
    import 'package:flutter_project/main.dart' as app;
    
    void main() {
      // This line enables the extension.
      enableFlutterDriverExtension();
    
      // Call the `main()` function of the app, or call `runApp` with
      // any widget you are interested in testing.
      app.main();
    }
    

    App_test.dart:

    import 'package:flutter_driver/flutter_driver.dart';
    import 'package:test/test.dart';
    
    void main() {
      group('MyApp', () {
        FlutterDriver driver;
    
        setUpAll(() async {
          driver = await FlutterDriver.connect();
        });
    
        // Close the connection to the driver after the tests have completed.
        tearDownAll(() async {
          if (driver != null) {
            driver.close();
          }
        });
      });
    }
    
    1. Run the test with flutter drive --target=test_driver/app.dart

    In my case the app is stuck at the await future for the *.json file from 1. Using the regular flutter run command everything works as expected.

    flutter doctor -v

    [✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.14.6 18G95, locale de-DE)
        • Flutter version 1.9.1+hotfix.2 at /Users/patrick/Development/flutter
        • Framework revision 2d2a1ffec9 (2 weeks ago), 2019-09-06 18:39:49 -0700
        • Engine revision b863200c37
        • Dart version 2.5.0
    
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        • Android SDK at /Users/patrick/Library/Android/sdk
        • Android NDK location not configured (optional; useful for native profiling support)
        • Platform android-29, build-tools 29.0.2
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 10.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 10.3, Build version 10G8
        • CocoaPods version 1.7.5
    
    [✓] Android Studio (version 3.5)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 39.0.3
        • Dart plugin version 191.8423
        • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    
    [✓] VS Code (version 1.38.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.4.1
    
    [✓] Connected device (2 available)
        • iPhone 7  • 5E5C912E-EA1D-438B-B5C5-E963D4BF9B33 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)
        • iPhone Xʀ • EE0825D6-B8B4-4010-B954-CC913953F5D4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)
    
    • No issues found!
    

    Has anybody a solution for that? The *.json I want to import is a config file, so it's critical for me to import it for a smooth running. Would be really glad about any workaround.

  • patreu22
    patreu22 over 4 years
    I've been able to solve the Json reading error by the IsolateWorkaround I found here: github.com/flutter/flutter/issues/24703, but unfortunately all my images are not loading anymore. Unluckily I can't share the complete code because it's from my work, so I shared the chunks I've been able to separate from the project.
  • George Herbert
    George Herbert over 4 years
    I see you raised an issue that was then linked to that issue. I am not sure if your issue is now related to this or a different issue. Maybe worth sharing your findings on 24703