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

Auto size text does not auto-size text in the Flutter stable v1.2.1 #10

Closed
jeffersonatsafe opened this issue Mar 27, 2019 · 12 comments
Closed
Labels
bug Something isn't working

Comments

@jeffersonatsafe
Copy link

I was on Flutter Beta 1.0 for the longest time in one of my machines.
Today I upgraded to Flutter Stable v1.2.1, and seems that this plugin has lost its functionality.
Text is not being auto-sized properly, even with maxLines and minFontSize specified.

plugin version: 1.1.1

code snippet:

        Card(
          margin: EdgeInsets.only(top: 12.0),
          elevation: 4.0,
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: AutoSizeText(
              "this is a very very very very very very very very very very long string",
              maxLines: 1,
              minFontSize: 2.0,
            ),
          ),
        ),

flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17134.648],
    locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.3)
[√] IntelliJ IDEA Community Edition (version 2018.1)
[√] Connected device (1 available)
@simc
Copy link
Owner

simc commented Mar 27, 2019

Please try wrapping your Card with a SizedBox.

@simc simc added the needs info Additional info is needed label Mar 27, 2019
@jeffersonatsafe
Copy link
Author

I've tried wrapping with a SizedBox, and then varying its width.

The text does resize with different width values, to a certain extent, but it still doesn't try to show the entire length of the string. It appears as if it's applying overflow truncation before resizing.

here's my modified code (with SizedBox) and a screenshot of what I'm seeing on my screen. I also varied the text scaling factor on the device to test this.

As seen in the screenshot, notice that the text is faded on the bottom. Does this mean that overflow has been applied to the text?

  @override
  Widget build(BuildContext context) {
    var stackContents = [
        SizedBox(
          width: 240,
          child: Card(
            margin: EdgeInsets.only(top: 12.0),
            elevation: 4.0,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: AutoSizeText(
                "hello kind sir, thank you, good bye",
//                "${_selectedLocation.latitude}, ${_selectedLocation.longitude}",
                maxLines: 1,
                maxFontSize: 24.0,
                overflow: TextOverflow.fade,
                minFontSize: 2.0,
              ),
            ),
          ),
        ),
    ];
    return Scaffold(
      appBar: AppBar(
        title: Text("Select Location"),
      ),
      body: Stack(
        children: stackContents,
      ),
    );

screenshot:
Screenshot-20190327-155617

@no-response no-response bot removed the needs info Additional info is needed label Mar 27, 2019
@simc
Copy link
Owner

simc commented Mar 28, 2019

Thanks for the information. I'll investigate this problem.

@simc simc added the wip This issue is currently being implemented label Mar 28, 2019
@simc
Copy link
Owner

simc commented Mar 28, 2019

I sadly cannot reproduce your problem. I tried it with multiple flutter versions including v1.2.1 and v1.4.2-pre.3. The text always resizes and fits the card.
I used this code from your sample:

class App extends StatefulWidget {
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {

  @override
  Widget build(BuildContext context) {
    var stackContents = [
      SizedBox(
        width: 180,
        child: Card(
          margin: EdgeInsets.only(top: 12.0),
          elevation: 4.0,
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: AutoSizeText(
              "hello kind sir, thank you, good bye",
              maxLines: 1,
              maxFontSize: 24.0,
              overflow: TextOverflow.fade,
              minFontSize: 2.0,
            ),
          ),
        ),
      ),
    ];

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Select Location"),
        ),
        body: Stack(
          children: stackContents,
        ),
      ),
    );
  }
}

Maybe try it with an empty project. If you still have problem it would be nice if you could share a sample project so I can reproduce the problem.

@simc simc added the needs info Additional info is needed label Mar 28, 2019
@jeffersonatsafe
Copy link
Author

thanks for looking into this!
Sadly, I'm still experiencing this problem, even in a relatively barebones project.
I've applied AutoSizeText to Flutter's getting_started project here:
https://github.com/jeffersonatsafe/flutterAutoSizeTextIssue

this is a screenshot of the project on a Galaxy S9, with font size (on the device) 4th from the left.
The three lines share the same minFontSize, only differing in SizedBox width.
Notice that the second line, although has more width than the first line, truncates more words.
Screenshot-20190328-104719

@no-response no-response bot removed the needs info Additional info is needed label Mar 28, 2019
@jeffersonatsafe
Copy link
Author

jeffersonatsafe commented Mar 28, 2019

update:
I think I might be wrong in assuming that the Flutter update caused this.
I rolled back to 1.0.0, and the issue is still there.

I think increasing the font size in the device itself is causing this problem, and I can't seem to recall if I tested with device font sizes in older flutter builds. This might not be a regression issue after all.
edit: I managed to find an older APK and indeed this was working as intended at some point, even with larger device font sizes

On Android devices, changing the device's display size (not font size) seem to work well. It's when I was changing the device's font size that this issue start to happen.

The issue also occurs on iOS device when using Accesibility > Larger Text settings.

@jeffersonatsafe
Copy link
Author

ok I've done more investigation, and I see that flutter update did not cause this.
Something caused this between auto_size_text v1.0.0 and auto_size_text_v1.1.1
I rolled back to 1.0.0 and the problem went away.

@simc
Copy link
Owner

simc commented Mar 31, 2019

Sorry for the late response, I'm very busy currently. It may take a few more days to fix this...

@simc simc closed this as completed in 2b3ed87 Apr 5, 2019
@simc
Copy link
Owner

simc commented Apr 5, 2019

I found the problem and fixed it. Thanks for your help. The new version (1.1.2) should be available soon. Please reopen the issue if it still doesn't work for you.

@simc simc added bug Something isn't working and removed wip This issue is currently being implemented labels Apr 5, 2019
@mahmoudsalah37
Copy link

it is not work with me inside Expanded

@giandifra
Copy link

giandifra commented Apr 8, 2020

It's pretty strange, I pass a variable to AutoSizeText widget and it not work, if i pass it a string it work!

Don't work

...
Container(
                      color: Colors.red,
                      height: 40,
                      child: AutoSizeText(
                        link,
                        maxLines: 1,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontSize: 30, fontWeight: FontWeight.bold),
                      ),
                    ),
...

Work:

...
Container(
                      color: Colors.red,
                      height: 40,
                      child: AutoSizeText(
                        'https://example.com/example',
                        maxLines: 1,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontSize: 30, fontWeight: FontWeight.bold),
                      ),
                    ),
...

PS: The Container is into a Column

Flutter Channel stable, v1.12.13+hotfix.8

@EliaTolin
Copy link

It's pretty strange, I pass a variable to AutoSizeText widget and it not work, if i pass it a string it work!

Don't work

...
Container(
                      color: Colors.red,
                      height: 40,
                      child: AutoSizeText(
                        link,
                        maxLines: 1,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontSize: 30, fontWeight: FontWeight.bold),
                      ),
                    ),
...

Work:

...
Container(
                      color: Colors.red,
                      height: 40,
                      child: AutoSizeText(
                        'https://example.com/example',
                        maxLines: 1,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontSize: 30, fontWeight: FontWeight.bold),
                      ),
                    ),
...

PS: The Container is into a Column

Flutter Channel stable, v1.12.13+hotfix.8

You have fix that?
I have the same problem.

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

5 participants