Repository: flutter/flutter
File: packages/flutter/test/widgets/autocomplete_test.dart (Dart)

Code before:

    // Focus the field to trigger optionsBuilder.
    await tester.tap(find.byType(TextField));
    await tester.pump();

    // Dispose the widget while optionsBuilder is still pending.
    setState(() {
      showAutocomplete = false;
    });
    await tester.pump();

    optionsCompleter.complete(<String>['option1', 'option2']);
    await tester.pump();

    expect(tester.takeException(), isNull);
  });

  testWidgets('Options view is constrained by MediaQuery bottom padding and view insets', (
    WidgetTester tester,
  ) async {
    const padding = 50.0;
    const bottomInsets = 70.0;
    tester.view.devicePixelRatio = 1.0;
    addTearDown(tester.view.reset);
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: Column(
            children: <Widget>[
              const SizedBox(height: 200),
              RawAutocomplete<String>(
                optionsBuilder: (TextEditingValue textEditingValue) => <String>['abcd'],
                fieldViewBuilder:
                    (
                      BuildContext context,
                      TextEditingController textEditingController,
                      FocusNode focusNode,
                      VoidCallback onFieldSubmitted,
                    ) {
                      return TextField(
                        controller: textEditingController,
                        focusNode: focusNode,
                        onSubmitted: (String value) {
                          onFieldSubmitted();
                        },
                      );
                    },
                optionsViewBuilder:
                    (
                      BuildContext context,
                      AutocompleteOnSelected<String> onSelected,

Review comment (refactor):
Can you use non-material widgets in this test? I.e. TestWidgetsApp and TestTextField?

RawAutocomplete is not material specific. We're in the process of trying to avoid Material imports in flutter/widgets.

While there are Material imports for the other tests in this file, I'd like to avoid introducing new Material widgets, for the clean up efforts, once someone gets to this file.

Code after:
    );

    // Focus the field to trigger optionsBuilder.
    await tester.tap(find.byType(TextField));
    await tester.pump();

    // Dispose the widget while optionsBuilder is still pending.
    setState(() {
      showAutocomplete = false;
    });
    await tester.pump();

    optionsCompleter.complete(<String>['option1', 'option2']);
    await tester.pump();

    expect(tester.takeException(), isNull);
  });

  testWidgets('Options view is constrained by MediaQuery bottom padding and view insets', (
    WidgetTester tester,
  ) async {
    const padding = 50.0;
    const bottomInsets = 70.0;
    tester.view.devicePixelRatio = 1.0;
    addTearDown(tester.view.reset);
    await tester.pumpWidget(
      TestWidgetsApp(
        home: Column(
          children: <Widget>[
            const SizedBox(height: 200),
            RawAutocomplete<String>(
              optionsBuilder: (TextEditingValue textEditingValue) => <String>['abcd'],
              fieldViewBuilder:
                  (
                    BuildContext context,
                    TextEditingController textEditingController,
                    FocusNode focusNode,
                    VoidCallback onFieldSubmitted,
                  ) {
                    return TestTextField(controller: textEditingController, focusNode: focusNode);
                  },
              optionsViewBuilder:
                  (
                    BuildContext context,
                    AutocompleteOnSelected<String> onSelected,
                    Iterable<String> options,
                  ) => const Placeholder(),
            ),
            const SizedBox(height: 200),
          ],
        ),