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

AutoSizeText.rich only working when style is defined both in AutoSizeText and TextSpan #7

Closed
Koridev opened this issue Mar 26, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@Koridev
Copy link

Koridev commented Mar 26, 2019

When using AutoSizeText.rich, it seems that I can only have correct autosizing when the fontSize is declared both in the AutoSizeText's style and in the TextSpan's, unlike what is said in the documentation.

A short sample to test it:

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: true,
      appBar: AppBar(
        title: TextField(),
      ),
      body: SafeArea(
        child: Column(children: <Widget>[
          Expanded(child: Center(child: SizedBox(width: 200, height: 200, child: AutoSizeText.rich(TextSpan(text: "Style is defined only in AutoSizeText",), style: TextStyle(fontSize: 200),),),),),
          Expanded(child: Center(child: SizedBox(width: 200, height: 200, child: AutoSizeText.rich(TextSpan(text: "Style is defined only in TextSpan", style: TextStyle(fontSize: 200)),),),),),
          Expanded(child: Center(child: SizedBox(width: 200, height: 200, child: AutoSizeText.rich(TextSpan(text: "Style is define in both AutoSizeText and TextSpan", style: TextStyle(fontSize: 200)), style: TextStyle(fontSize: 200),),),),),
        ],),
      ),
    );
  }
}

Only the last widget of the Column will be auto sized.

Using auto_size_text: ^1.1.0

@simc
Copy link
Owner

simc commented Mar 26, 2019

Thanks for reporting this. I'll fix it 👍

@simc
Copy link
Owner

simc commented Mar 27, 2019

The case where only AutoSizeText has a style was a bug that I fixed.

The other case wasn't: Since your AutoSizeText doesn't have a style, the default style is used (probably fontSize = 14). To fit the large span, AutoSizeText has to scale the text down. But the default minFontSize is 12 and since the "reference fontSize" is 14, the text is not scaled down very far. Just set minFontSize to 0.1 and it will work.
Note: You probably also have to use a smaller stepGranularity (like 0.1) because the steps will be very large.

It would be very helpful if you could verify that the first case is fixed before I release a new version.

Just add this to your dependecies:

dependencies:
  auto_size_text:
    git:
      url: git://github.com/leisim/auto_size_text.git
      ref: style-fix

Edit: I added a troubleshooting guide for the second case.

@simc simc added the bug Something isn't working label Mar 27, 2019
@Koridev
Copy link
Author

Koridev commented Mar 27, 2019

Yes, the fix works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants