Skip to content
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

support shrinkToFit property in 1.0.0 #297

Closed
Digoun opened this issue May 20, 2020 · 2 comments · Fixed by #530
Closed

support shrinkToFit property in 1.0.0 #297

Digoun opened this issue May 20, 2020 · 2 comments · Fixed by #530

Comments

@Digoun
Copy link

Digoun commented May 20, 2020

It seems the property shrinkToFit from the old RichText parser is not supported anymore in latest version 1.0.0, but it wasn't mentioned in the migration guide.
I'm still quite new user of this library, what is the best way to avoid having the Html widget using a double.infinity width ?

Maybe would it make sense to add back support for this property shrinkToFit in the SizeBox to avoid having double.infinity?

Something in that mind maybe:

class StyledText extends StatelessWidget {
  final InlineSpan textSpan;
  final Style style;
  final bool shrinkToFit;

  const StyledText({
    this.textSpan,
    this.style,
    this.shrinkToFit = false
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: (style.display == Display.BLOCK || style.display == Display.LIST_ITEM) && !this.shrinkToFit
          ? double.infinity
          : null,
      child: Text.rich(
        textSpan,
        style: style.generateTextStyle(),
        textAlign: style.textAlign,
        textDirection: style.direction,
      ),
    );
  }
}

Thanks in advance for your suggestions.

@ryan-berger
Copy link
Collaborator

@Digoun That would definitely cause a problem for apps where a width of double.infinity could cause the Flutter's layout builder to crash.

Although I am the current maintainer, I am quite new to the library as well. After a bit of research into Flutter's SizedBox looks like this bit of code you provided would work, but I would need to go and take a look and see if it would break anything. If it doesn't, I think this bit of code could be implemented pretty easily.

@Digoun
Copy link
Author

Digoun commented Jun 14, 2020

Thank you @ryan-berger for your reply, I really appreciate it.
I hope this change won't break anything, I can't wait to see it implemented :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants