Skip to content

flutter can't be imported into an integration test #111833

Description

@isaaclyman

If you try to import e.g. 'package:flutter/material.dart'; in any file that isn't part of a running Flutter application, you get the following error:

Crash when compiling null,
at character offset null:
Null check operator used on a null value
#0      InferableTypeBuilderMixin.type (package:front_end/src/fasta/builder/type_builder.dart:392:29)

The error doesn't contain any information that would help someone fix it, but at this point I've seen it enough to know what it is. I've learned to expect it when I try to refer to Flutter (even just for type checking) in any script or file outside my Flutter application.

However, I didn't expect to see it in a simple integration test:

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'package:my_app/main.dart' as app;

void main() {
  final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  testWidgets('my first test', (tester) async {
    app.main();

    await tester.pumpAndSettle();
    if (tester.allWidgets
        .any((w) => w.runtimeType == CircularProgressIndicator)) {
      await Future.delayed(const Duration(seconds: 1));
    }
    print('Progress finished');
  });
}

This may not be a recommended thing to do in a test, but since the WidgetTester lets you query the widget tree it's very odd that it can't actually refer to Flutter. When you run this with flutter drive --driver=test_driver/integration_test.dart --target=integration_test/screenshots.dart (using the standard test driver definition as seen in the integration_test documentation), you get the error I referenced earlier.

Is this error intended behavior? Is it possible to refer to Flutter types in integration tests (or other scripts) and I'm just too new to Dart to know how?

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependency: dartDart team may need to help usf: integration_testThe flutter/packages/integration_test pluginr: fixedIssue is closed as already fixed in a newer version

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions