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
The message means that the function
expect
is defined two times. Once inwidget_tester.dart
and once inexpect.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 addas prefix
That means that you could for example changeto
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 writeIt means the function
expect
is defined in two places: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: