How to make widget tests in flutter run if it gives the following error?

Issue

My test already worked, but when I upgraded Flutter to a new version it gives an error when I run it from command line with

flutter test test/widget_test.dart

The error is

00:05 +0 -1: loading /Users/lenz/plug_and_plink/test/widget_test.dart [E]                                                                                                                           
  Failed to load "/Users/lenz/project/test/widget_test.dart": type '(WidgetTester) => Future<Null>' is not a subtype of type '() => dynamic'
  package:flutter_test/src/test_compat.dart 171:29  test
  test/widget_test.dart 53:3                        main

00:05 +0 -1: Some tests failed. 

When I try to run the test from Android studio UI it gives another error:

file:///Users/lenz/development/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show Paint, Path, Canvas;
       ^
file:///Users/lenz/development/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///Users/lenz/development/flutter/packages/flutter/lib/src/material/app.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;

And a lot more lines about ‘dart:ui’
What to do to make it work again?

Solution

I solved the problem by deleting /bin/cache/ folder in flutter directory. After this it is required to run

flutter precache

from command line. Seems like these files were not updated when flutter was upgraded

Answered By – Valentina Konyukhova

Answer Checked By – David Goodson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.