question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

widget_test.dart generates console errors in IntelliJ project

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
pqcommented, Oct 25, 2017

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…

0reactions
craiglabenzcommented, Nov 10, 2018

For what it’s worth, I am following tutorials Codelabs tutorials like this one and began running into this problem immediately. It wasn’t until I found this thread that I was certain I wasn’t doing something horribly, horribly wrong.

The error does also seem to still lock up hot reloading, requiring a simulator restart.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run/Debug Configuration: Dart Test | IntelliJ IDEA ... - JetBrains
In this dialog, create configurations for running and debugging Dart tests that are written using the dart test package.
Read more >
how to remove this error from intelliJ console flutter
Right click and choose 'Fold Lines Like This'.
Read more >
test | Dart Package - Pub.dev
However, it may be useful when testing APIs that are meant to be used by JavaScript code. The test runner looks for an...
Read more >
flutter create is not a valid dart package name. - You.com
I cloned the repo, and want to update android/ios directory, however I got "flutter-boilerplate-project" is not a valid Dart package name. error.
Read more >
Android Studio and IntelliJ - Flutter documentation
If dart or flutter are listed, update them. Creating projects. You can create a new project in one of several ways. Creating a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found