Reputation: 222
I am currently writing tests for a dropdown for my flutter app.
In this app I have a CustomDropdownButton2 to change the language of the app. It contains strings for the different language.
My test for this looks like this so far:
testWidgets('Language change test', (WidgetTester tester) async {
// Build app and trigger frame rebuild
await tester.pumpWidget(
EasyLocalization(
path: 'assets/languages',
supportedLocales: L10n.all,
fallbackLocale: const Locale('de', 'DE'),
child: makeTestableWidget(
ChangeNotifierProvider<Settings>(
create: (_) => Settings(),
child: const SettingsPage(),
),
),
),
);
// wait for it to finish
await tester.pumpAndSettle();
// Since german is the default language, this should be displayed
expect(find.text('Einstellungen'), findsOneWidget);
await tester.tap(find.byKey(const Key('LanguageDropdown')));
await tester.pumpAndSettle();
tester.ensureVisible(find.text('English').last);
await tester.pumpAndSettle();
await tester.tap(find.text('English').last); // this is the part where the warning is thrown
});
It throws the warning A call to tap() with finder "exactly one widget with text "English" (ignoring all but last) (ignoring offstage widgets): Text("English", inherit: true, size: 14.0, overflow: ellipsis, maxLines: 1, dependencies: [DefaultSelectionStyle, DefaultTextStyle, MediaQuery, _ScrollableScope])" derived an Offset (Offset(91.0, 200.0)) that would not hit test on the specified widget.
I have tried out the solution from this and this question, but no luck so far.
Upvotes: 1
Views: 620
Reputation: 143
Workaround for this is to have a long enough text in the DropdownMenuItem, e.g. "Really long string to be clicked successfully" - the length depends on your tester surfaceSize.
Possible reason: it seems like the items don't fill the width of the menu but the hit area is cut off where text ends.
Upvotes: 0