skip to Main Content

Error: The name ‘expect’ is defined in the libraries
‘package:flutter_test/src/widget_tester.dart (via
package:flutter_test/flutter_test.dart)’ and
‘package:test_api/src/expect/expect.dart’. Try using ‘as prefix’ for
one of the import directives, or hiding the name from all but one of
the imports.

Code:

testWidgets("TEST WÄ°DGET SUCCESS", (widgetTester) async {
      await tester.pumpWidget(const MyHomePage(title: 'Ti', mesaj: 'Msg'));

      final titleFind = find.text("Ti");
      final MesajFind = find.text("msg");

      expect(titleFind, findsOneWidget);
      expect(, matcher)
    });
Image:
[enter image description here][1]

2

Answers


  1. The message means that the function expect is defined two times. Once in widget_tester.dart and once in expect.dart. Because of this it doesn’t know which of the two it should use. To solve it you could try leave out one of the import statements if you’re not using it for other reasons or as the error message suggest to add as prefix That means that you could for example change

    import 'package:test_api/src/expect/expect.dart';
    

    to

    import 'package:test_api/src/expect/expect.dart' as whateverYouLike;
    

    and then where you want to use functions of that file prefix it with that like whateverYouLike.expect()

    Or for the one that you don’t want to use the expect() function of you write

    import 'package:test_api/src/expect/expect.dart' hide expect;
    
    Login or Signup to reply.
  2. It means the function expect is defined in two places:

    1. flutter_test.dart, and
    2. test_api/src/expect/expect.dart

    The compiler is confused on which definition to use. Please remove test_api/src/expect/expect.dart if it is not required. If it is required, please give it in alias like this:

    import 'package:test_api/src/expect/expect.dart' as test_api
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search