flutter-intellij: widget_test.dart generates console errors in IntelliJ project

Steps to Reproduce

  1. Create a new Flutter project in IntelliJ.
  2. Open lib/main.dart and replace the contents of the default sample app MyApp.
  3. Get the following errors in the console (because widget_test.dart is referring to class MyApp):
error: Undefined class 'MyApp'. (undefined_class at [testing] test/widget_test.dart:15)
error: The constructor returns type 'dynamic' that isn't of expected type 'Widget'. (strong_mode_invalid_cast_new_expr at [testing] test/widget_test.dart:15)
info: Unused import. (unused_import at [testing] test/widget_test.dart:10)

Also get red wavy underline under the <project name> and the test directory. The line in widget_test.dart causing the error is:

await tester.pumpWidget(new MyApp());

This doesn’t happen after the equivalent set of steps at the command line (flutter create, replace contents of main.dart, flutter run). No errors are printed to the console in that case.

Note that the app still runs; clicking the Run button on the toolbar still works. Running the app makes the console errors go away. But the red wavy underlines in the left nav persist, and it looks alarming - a new user will think they have to resolve these errors before they can run their first app.

https://github.com/flutter/flutter/pull/11304/files is where this was introduced.

Version info

[✓] Flutter (on Linux, locale en_US.UTF-8, channel alpha) • Flutter at /usr/local/google/home/eastrue/flutter • Framework revision 1c372c6803 (8 weeks ago), 2017-08-31 15:54:45 -0700 • Engine revision f9e00a7c72 • Tools Dart version 1.25.0-dev.11.0

[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3) • Android SDK at /usr/local/google/home/eastrue/Android/Sdk • Platform android-25, build-tools 25.0.3 • Java binary at: /opt/android-studio-with-blaze-2.3/jre/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] Android Studio (version 2.3) • Android Studio at /opt/android-studio-2.3 • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] Android Studio (version 2.3) • Android Studio at /opt/android-studio-with-blaze-2.3 • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] Android Studio (version 2.2) • Android Studio at /usr/local/google/home/eastrue/android-studio • Java version OpenJDK Runtime Environment (build 1.8.0_76-release-b03)

[-] IntelliJ IDEA Community Edition (version 2017.1) ✗ Flutter plugin not installed; this adds Flutter specific functionality. • Dart plugin version 171.4694.29 • For information about installing plugins, see https://flutter.io/intellij-setup/#installing-the-plugins

[✓] Connected devices • Nexus 5X • 0048fc9b7c76b7a2 • android-arm • Android 6.0.1 (API 23)

/cc @efortuna

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the report!

The issue here is that we generate a sample test with the sample app. When you follow the instructions in the tutorial you remove the class MyApp that is referenced in the sample test and so you get analysis errors.

I can think of a few approaches to smoothing this out. The easiest might be to update the tutorial contents to modify the test in one of a few ways.

  1. at the outset, instruct folks to remove the test altogether or alter its contents or more ambitiously
  2. add instructions to update it to work with the tutorial app (e.g., modify it to reference MaterialApp and do something sensible

The first is easiest…