-
-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration Tests do not work with AutoSizeText.rich(..) constructor #32
Comments
This code works fine: testWidgets('Uses textKey', (tester) async {
var key = GlobalKey();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: AutoSizeText.rich(
TextSpan(text: 'A rich text'),
textKey: key,
),
),
),
);
print(find.byKey(key).evaluate().first);
});
|
@leisim thanks for the fast answer. I see, the issue here is that for the RichText I use, I have to chain TextSpans. That's why I set the As far as I know, the only way to do this with RichText is to chain the TextSpans. And when you chain it, the key gets propagated to the wrong widget in the end. Actually, I am not sure if this is a problem of AutoSizeText or the RichText itself but I would guess most RichText use-cases are the way I use them - to format portions of the text. Because formatting a single line can also be done with a regular Text field. |
What happenes if you replace To be honest, I'm not that experienced with integration tests but I think that |
@leisim I now got it working (at least for widget tests). See my answer here, maybe it helps someone that also stumbles across this issue: https://stackoverflow.com/questions/51238526/testing-text-in-textspan/57860023#57860023 I could not yet figure it out for integration tests but at least I now know parts of it. So it's something that should be possible with dart itself. |
This is very late but maybe it can help someone else, as I went through the same issue. I was able to get the text like this:
Notice that the key property is the one set on AutoSizeText.rich() textKey property. Worked well for me. |
Steps to Reproduce
Thanks to #27 I wanted to now check strings in my integration tests with
driver.getText(myTextKeyFinder)
. Unfortunately, it does not seem to work withAutoSizeText.rich(..)
constructed AutoSizeText widgets.If I look at the tree with the Dart DevTools, the tree looks the following:
Obviously, if I then do the following:
it fails because the Text widget with the key has no text and the RichText with my text has no key.
So in this case I would expect the RichText widget to have receive the key. Then I guess it would work.
Code sample
Screenshots
N/A
Version
The text was updated successfully, but these errors were encountered: