Flutter widget that automatically resizes text to fit perfectly within its bounds.

Overview

GitHub Actions codecov Version GitHub license

Flutter widget that automatically resizes text to fit perfectly within its bounds.

Show some ❤️ and star the repo to support the project

Resources:

Also check out the blazing fast key-value store hive.

Contents

Usage

AutoSizeText behaves exactly like a Text. The only difference is that it resizes text to fit within its bounds.

AutoSizeText(
  'The text to display',
  style: TextStyle(fontSize: 20),
  maxLines: 2,
)

Note: AutoSizeText needs bounded constraints to resize the text. More info here.

maxLines

The maxLines parameter works like you are used to with the Text widget. If there is no maxLines parameter specified, the AutoSizeText only fits the text according to the available width and height.

AutoSizeText(
  'A really long String',
  style: TextStyle(fontSize: 30),
  maxLines: 2,
)

Sample above

minFontSize & maxFontSize

The AutoSizeText starts with TextStyle.fontSize. It measures the resulting text and rescales it to fit within its bonds. You can however set the allowed range of the resulting font size.

With minFontSize you can specify the smallest possible font size. If the text still doesn't fit, it will be handled according to overflow. The default minFontSize is 12.

maxFontSize sets the largest possible font size. This is useful if the TextStyle inherits the font size and you want to constrain it.

AutoSizeText(
  'A really long String',
  style: TextStyle(fontSize: 30),
  minFontSize: 18,
  maxLines: 4,
  overflow: TextOverflow.ellipsis,
)

group

You can synchronize the font size of multiple AutoSizeText. They will fit their boundaries and all AutoSizeText in the same group have the same size. That means they adjust their font size to the group member with the smallest effective font size.

Note: If a AutoSizeText cannot adjust because of constraints like minFontSize, it won't have the same size as the other group members.

An instance of AutoSizeGroup represents one group. Pass this instance to all AutoSizeText you want to add to that group. You don't have to care about disposing the group if it is no longer needed.

Important: Please don't pass a new instance of AutoSizeGroup every build. In other words, save the AutoSizeGroup instance in a StatefulWidget.

var myGroup = AutoSizeGroup();

AutoSizeText(
  'Text 1',
  group: myGroup,
);

AutoSizeText(
  'Text 2',
  group: myGroup,
);

stepGranularity

The AutoSizeText will try each font size, starting with TextStyle.fontSize until the text fits within its bounds.
stepGranularity specifies how much the font size is decreased each step. Usually, this value should not be below 1 for best performance.

AutoSizeText(
  'A really long String',
  style: TextStyle(fontSize: 40),
  minFontSize: 10,
  stepGranularity: 10,
  maxLines: 4,
  overflow: TextOverflow.ellipsis,
)

presetFontSizes

If you want to allow only specific font sizes, you can set them with presetFontSizes. If presetFontSizes is set, minFontSize, maxFontSize and stepGranularity will be ignored.

AutoSizeText(
  'A really long String',
  presetFontSizes: [40, 20, 14],
  maxLines: 4,
)

overflowReplacement

If the text is overflowing and does not fit its bounds, this widget is displayed instead. This can be useful to prevent text being too small to read.

AutoSizeText(
  'A String tool long to display without extreme scaling or overflow.',
  maxLines: 1,
  overflowReplacement: Text('Sorry String too long'),
)

Rich Text

You can also use Rich Text (like different text styles or links) with AutoSizeText. Just use the AutoSizeText.rich() constructor (which works exactly like the Text.rich() constructor).

The only thing you have to be aware of is how the font size calculation works: The fontSize in the style parameter of AutoSizeText (or the inherited fontSize if none is set) is used as reference.

For example:

AutoSizeText.rich(
  TextSpan(text: 'A really long String'),
  style: TextStyle(fontSize: 20),
  minFontSize: 5,
)

The text will be at least 1/4 of its original size (5 / 20 = 1/4).
But it does not mean that all TextSpans have at least font size 5.

Parameters

Parameter Description
key* Controls how one widget replaces another widget in the tree.
textKey Sets the key for the resulting Text widget
style* If non-null, the style to use for this text
minFontSize The minimum text size constraint to be used when auto-sizing text.
Is being ignored if presetFontSizes is set.
maxFontSize The maximum text size constraint to be used when auto-sizing text.
Is being ignored if presetFontSizes is set.
stepGranularity The step size in which the font size is being adapted to constraints.
presetFontSizes Predefines all the possible font sizes.
Important: presetFontSizes have to be in descending order.
group Synchronizes the size of multiple AutoSizeTexts
textAlign* How the text should be aligned horizontally.
textDirection* The directionality of the text. This decides how textAlign values like TextAlign.start and TextAlign.end are interpreted.
locale* Used to select a font when the same Unicode character can be rendered differently, depending on the locale.
softWrap* Whether the text should break at soft line breaks.
wrapWords Whether words which don't fit in one line should be wrapped. Defaults to true to behave like Text.
overflow* How visual overflow should be handled.
overflowReplacement If the text is overflowing and does not fit its bounds, this widget is displayed instead.
textScaleFactor* The number of font pixels for each logical pixel. Also affects minFontSize, maxFontSize and presetFontSizes.
maxLines An optional maximum number of lines for the text to span.
semanticsLabel* An alternative semantics label for this text.

Parameters marked with * behave exactly the same as in Text

Performance

AutoSizeText is really fast. In fact, you can replace all your Text widgets with AutoSizeText.
Nevertheless you should not use an unreasonable high fontSize in your TextStyle. E.g. don't set the fontSize to 1000 if you know, that the text will never be larger than 30.

If your font size has a very large range, consider increasing stepGranularity.

Troubleshooting

Missing bounds

If AutoSizeText overflows or does not resize the text, you should check if it has constrained width and height.

Wrong code:

Row(
  children: <Widget>[
    AutoSizeText(
      'Here is a very long text, which should be resized',
      maxLines: 1,
    ),
  ],
)

Because Row and other widgets like Container, Column or ListView do not constrain their children, the text will overflow.
You can fix this by constraining the AutoSizeText. Wrap it with Expanded in case of Row and Column or use a SizedBox or another widget with fixed width (and height).

Correct code:

Row(
  children: <Widget>[
    Expanded( // Constrains AutoSizeText to the width of the Row
      child: AutoSizeText(
        'Here is a very long text, which should be resized',
        maxLines: 1,
      )
    ),
  ],
)
}

Further explanation can be found here. If you still have problems, please open an issue.

MinFontSize too large

AutoSizeText does not resize text below the minFontSize which defaults to 12. This can happen very easily if you use AutoSizeText.rich():

Wrong code:

AutoSizeText.rich(
  TextSpan(
    text: 'Text that will not be resized correctly in some cases',
    style: TextStyle(fontSize: 200),
  ),
)

This rich text does not have a style so it will fall back to the default style (probably fontSize = 14). It has an implicit minFontSize of 12 that means it can be resized to 86% of its original size at the most (14 -> 12). Just set minFontSize = 0 or add style: TextStyle(fontSize: 200) to the AutoSizeText.

Note: If you use the first option, you should also consider lowering stepGranularity. Otherwise the steps of resizing will be very large.

Correct code:

AutoSizeText.rich(
  TextSpan(
    text: 'Text that will be resized correctly',
    style: TextStyle(fontSize: 200),
  ),
  minFontSize: 0,
  stepGranularity: 0.1,
)

MIT License

Copyright (c) 2018 Simon Leier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Comments
  • Don't wrap long words

    Don't wrap long words

    Problem When trying to display text that contains long words using the AutoSizeText widget, it can get wrapped if the available space is small. Perhaps there are some places where this is the intended effect, but in most cases, it's not. Design-wise, this is very dangerous because often, apps display data that's unknown at compile-time, so most developers probably aren't even aware of this behavior. That's why I propose to present an option to the developer (perhaps a wrapWords in the constructor) that lets the user opt-in to word-wrapping, making not wrapping words the default.

    The technical side So how is it possible to not wrap words? Let's suppose you calculated a seemingly fitting text size. The following is one possible way of making sure the text doesn't wrap:

    1. Break the text into separate lines by replacing every section of whitespaces with newlines (\n).
    2. Create a TextPainter for the text, setting the maxLines property to the number of words.
    3. Measure the text again with the incoming width.
    4. If the text didExceedMaxLines, a word got wrapped! Otherwise, we're good.
    5. If a word got wrapped, try the same for a smaller text.

    Possible concerns The only possible contra argument that comes to my mind is that the widget is less performing. But as the widget isn't heavily optimized for performance yet (i.e. linear search for the text size is used instead of binary search), and the decision making for the text size doesn't happen often, I'm sure it's a trade-off worth making.

    Implementation So, how do you feel about this proposal? If you do agree that this would be a nice feature to have, would you like to implement it or should I do so and then, file a pull request? (Could take some time, I'm currently quite busy.)

    enhancement 
    opened by MarcelGarus 12
  • Auto size text does not auto-size text in the Flutter stable  v1.2.1

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

    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)
    
    bug 
    opened by jeffersonatsafe 12
  • Error calculating dimensions in SimpleDialog

    Error calculating dimensions in SimpleDialog

    Steps to Reproduce

    • Create a SimpleDialog being shown in the showDialog call.
    • In the title add a row with an expanded widget which holds the AutoSizeText widget

    Code sample

    Container(
                color: Colors.black12,
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Expanded(
                      child: Padding(
                        padding:
                            const EdgeInsets.only(left: 10, top: 10, bottom: 5),
                        child: AutoSizeText(
                           "Big long huge title here to shrink",
                          style: Theme.of(context).textTheme.title,
                          minFontSize: 14,
                          maxLines: 1,         
                        ),
                      ),
                    ),
                    IconButton(
                      alignment: Alignment.topRight,
                      icon: Icon(Icons.close),
                      onPressed: () => Navigator.of(context).pop(),
                    )
                  ],
                ),
              ),
    

    Screenshots If applicable, add screenshots to help explain your problem.

    Version

    • Flutter version: [1.5.4]
    • auto_size_text version: [2.0.1]
    bug wip 
    opened by warriorCoder 9
  • FontSize has to be multiples of stepGranularity

    FontSize has to be multiples of stepGranularity

    I've had this error after I upgraded the package to 2.0.0+2. Also, I've never changed my code. This one used to work in the previous version:

    Code sample

    AutoSizeText(
         "Here is a long text.",
         textAlign: TextAlign.center,
         minFontSize: 16.0,
         maxLines: 4, 
         overflow: TextOverflow.ellipsis,
    ),
    
    flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
    flutter: The following assertion was thrown building LayoutBuilder:
    flutter: FontSize has to be multiples of stepGranularity.
    flutter: 'package:auto_size_text/src/auto_size_text.dart': Failed assertion: line 296 pos 14: 'style.fontSize
    flutter: / widget.stepGranularity % 1 == 0'
    flutter:
    flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
    flutter: more information in this error message to help you determine and fix the underlying cause.
    flutter: In either case, please report this assertion by filing a bug on GitHub:
    flutter:   https://github.com/flutter/flutter/issues/new?template=BUG.md
    flutter:
    flutter: When the exception was thrown, this was the stack:
    flutter: #2      _AutoSizeTextState._sanityCheck (package:auto_size_text/src/auto_size_text.dart:296:14)
    flutter: #3      _AutoSizeTextState.build.<anonymous closure> (package:auto_size_text/src/auto_size_text.dart:253:7)
    flutter: #4      _LayoutBuilderElement._layout.<anonymous closure> (package:flutter/src/widgets/layout_builder.dart:113:26)
    flutter: #5      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2258:19)
    flutter: #6      _LayoutBuilderElement._layout (package:flutter/src/widgets/layout_builder.dart:109:11)
    flutter: #7      RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1740:58)
    flutter: #8      PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:797:15)
    flutter: #9      RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1740:13)
    flutter: #10     _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:207:5)
    flutter: #11     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #12     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #13     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #14     RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:385:13)
    flutter: #15     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #16     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
    flutter: #17     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #18     RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:259:13)
    flutter: #19     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #20     RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:385:13)
    flutter: #21     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #22     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
    flutter: #23     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:431:7)
    flutter: #24     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
    flutter: #25     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
    flutter: #26     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #27     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #28     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #29     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #30     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1206:11)
    flutter: #31     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #32     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #33     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #34     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #35     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #36     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #37     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #38     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
    flutter: #39     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #40     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #41     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #42     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #43     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #44     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #45     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #46     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #47     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #48     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #49     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #50     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #51     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3015:13)
    flutter: #52     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #53     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
    flutter: #54     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #55     __RenderTheatre&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #56     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #57     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #58     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #59     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #60     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #61     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #62     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #63     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
    flutter: #64     RenderObject.layout (package:flutter/src/rendering/object.dart:1644:7)
    flutter: #65     RenderView.performLayout (package:flutter/src/rendering/view.dart:151:13)
    flutter: #66     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1519:7)
    flutter: #67     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:766:18)
    flutter: #68     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:347:19)
    flutter: #69     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:701:13)
    flutter: #70     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
    flutter: #71     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
    flutter: #72     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9)
    flutter: #73     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:773:7)
    flutter: #82     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
    flutter: #83     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
    flutter: #84     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)
    flutter: (elided 10 frames from class _AssertionError, package dart:async, and package dart:async-patch)
    flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
    

    Version

    • Flutter version: 1.5.4
    • auto_size_text version: 2.0.0+2
    question 
    opened by afnx 8
  • Android bug what is it?

    Android bug what is it?

    Container(
                            height: 50,
                            width: 40,
                            alignment: Alignment.center,
                            child: AutoSizeText(
                              '999',
                              style: TextStyle(fontSize: 100),
                              textAlign: TextAlign.center,
                              maxLines: 1,
                            ),
                          ),
    

    This code works fine in any IOS device, but on Android, the last letter goes to the next line, if you slightly increase the height you will see why this happens? But FittedBox help this

    question 
    opened by 1AlexFix1 8
  • Failing tests for version 0.2.0

    Failing tests for version 0.2.0

    The tests are failing for the 0.2.0 release: https://travis-ci.com/leisim/auto_size_text/builds/85639827

    Is the version 0.2.0 supposed to work? I can't get it to work. Even when I'm trying something like AutoSizeText('foo', minFontSize: 50.0, maxFontSize: 100.0) the text is rendered at the default font size (12.0).

    bug 
    opened by apaatsio 7
  • AutoSizeText cannot be properly tested in Integration tests

    AutoSizeText cannot be properly tested in Integration tests

    Is your feature request related to a problem? Please describe. AutoSizeText has a key, but using the key we cannot get text in Integration test. As await driver.getText(finder) can get text from a Text type widget and not from custom widget which is not a subtype of text.

    Though we can do await driver.waitFor(find.text("text")); but this is not appropriate as a page can have multiple places with same text and it is best to find text using a key finder.

    Describe the solution you'd like Passing a separate key parameter in AutoSizeText widget for the Text widget defined inside AutoSizeText library can let us find the text from the key for Text widget.

    Version

    • Flutter version: v1.7.4
    • auto_size_text version: 2.0.2+1

    Error:

    DriverError: Error in Flutter application: Uncaught extension error while executing get_text: type 'AutoSizeText' is not a subtype of type 'Text'
      #0      FlutterDriverExtension._getText (package:flutter_driver/src/extension/extension.dart:446:16)
      <asynchronous suspension>
      #1      FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:188:53)
      <asynchronous suspension>
      #2      BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:512:32)
      <asynchronous suspension>
      #3      _runExtension (dart:developer-patch/developer.dart:84:23)
    
      Original error: null
      Original stack trace:
      null
    
    enhancement 
    opened by vishaldhudum 6
  • Would be nice to have a way to coordinate font autosizing across multiple widgets

    Would be nice to have a way to coordinate font autosizing across multiple widgets

    I have a bunch of widgets where I would like to have the text be as large as possible but the font size needs to be the same for all the widgets.

    Basically want a way to say that the widgets share an autosize controller and the font is set to the minimum font size across all the widgets.

    enhancement 
    opened by dalewking 6
  • Integration Tests do not work with AutoSizeText.rich(..) constructor

    Integration Tests do not work with AutoSizeText.rich(..) constructor

    Steps to Reproduce Thanks to https://github.com/leisim/auto_size_text/issues/27 I wanted to now check strings in my integration tests with driver.getText(myTextKeyFinder). Unfortunately, it does not seem to work with AutoSizeText.rich(..) constructed AutoSizeText widgets.

    If I look at the tree with the Dart DevTools, the tree looks the following:

    • AutoSizeText
      • LayoutBuilder
        • Text [myTextKey]
          • RichText (this one has no key)
            • text: Here is my text

    Obviously, if I then do the following:

    String myElementText = await driver.getText(myTextKeyFinder);
    expect(myElementText , 'My Text');
    

    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

    AutoSizeText.rich(
            TextSpan(
              style: _style,
              children: getStyledSpans( //getStyledSpans is a List<TextSpan>
                _text,
                _style,
              ),
            ),
            textAlign: _textAlign,
            maxLines: _maxLines,
            textKey: _textKey,
          ),
    

    Screenshots N/A

    Version

    • Flutter version: 1.7.8+hotfix.4
    • auto_size_text version: 2.1.0
    bug 
    opened by sceee 5
  • Incorrect styling when using a theme switching toggle

    Incorrect styling when using a theme switching toggle

    I'm writing an app for my workplace that has a light theme/dark theme toggle switch in a scaffold drawer. I've wrapped most of the text in the app with this widget for string length differences when localizing to other languages. Its been very helpful, but I'm finding that when i use the theme toggle the text colors aren't changing correctly. When loading a page in the app, the text is correctly contrasting against the background (black text on white BG and white text on grey BG) but once the theme toggle is activated the text then matches the background (black text on grey BG and white text on white BG). For reference, I've tried using this widget with two different theme toggling examples I've found online as a way to check if my implementation was causing the issue but its consistent with both of them. The two examples I used can be found at the following github repos

    https://github.com/jorgecoca/theme_switcher/tree/theme-switcher-tutorial-1 https://github.com/iampawan/Flutter-Dynamic-Theming

    if i need to provide anymore information, please let me know.

    bug 
    opened by mac6288 4
  • Does not work correctly with large fonts setting

    Does not work correctly with large fonts setting

    Android devices (and I assume iOS devices as well) have a setting to control font sizing so that if you have trouble seeing you can scale fonts up across the entire device. When this is enabled on a device, it is not taken into account in this library so that this library determines the font size that will fit but then it gets scaled up from there.

    You can read about this setting from a flutter perspective in this article in the section on Large Fonts: https://medium.com/flutter-community/a-deep-dive-into-flutters-accessibility-widgets-eb0ef9455bc

    opened by dalewking 4
  • Text scaling is not working on iOS

    Text scaling is not working on iOS

    Steps to Reproduce On Samsung phone (e.g, s8), text scaling is not working properly

    Screenshots On all iOS and most the Android phones, scaling is working just fine image But for Samsung, there is the issue image

    Version

    • Flutter version: 3.3.9
    • auto_size_text version: 3.0.0
    bug 
    opened by AndreyKomarichev10 0
  • Get Font Size

    Get Font Size

    Would like a feature to get the font-size used after layout. This is so I can standardize the font-size in adjacent boxes (on same page)

    GlobalKey  textKey = GlobalKey();
    WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
    
       test.getActualFontSizeUsed();
    
    });
    
    // In build
    Widget test =  AutoSizeText(
       'Trying to get Font Size',
       key: textKey,
    );
    
    
    enhancement 
    opened by yosus 1
  • AutoSizeGroup doesn't work on web/Android

    AutoSizeGroup doesn't work on web/Android

    Steps to Reproduce

    • create a project with the code below
    • build it using flutter build web
    • put the build/web directory on a webserver
    • access this url from both chrome/Linux (works fine) and from chrome/Android (does not work)

    The code below runs fine

    • on web(chrome)/Linux
    • on Android (as app)
    • but NOT on web(chrome)/Android In the later case, the autosizing does not seem to work.

    Code sample

          body: Row(
            children:[
              Spacer(flex:3),
              Expanded(child: Card(child: AutoSizeText("aaa", group: autoSizeGroup, maxLines:1, minFontSize: 6, style: textStyle))),
              Expanded(child: Card(child: AutoSizeText("somewhat longer", group: autoSizeGroup, maxLines: 1, minFontSize: 6, style: textStyle))),
              Spacer(flex:3)
            ]
          ),
    

    Screenshots If applicable, add screenshots to help explain your problem. Screenshot added from linux chrome browser and Android chrome browser. Same problem is observed on iOS/Chrome+safari image Screenshot_20221026-164845_Chrome

    Version

    • auto_size_text version: 3.0.0
    • Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.5, on Linux Mint 20.2 5.15.0-46-generic, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2022.1) [✓] VS Code (version 1.70.1) [✓] Connected device (2 available) [✓] HTTP Host Availability
    bug 
    opened by MarcVanDaele90 2
  • Autosize text widget doesn't return text value with getText() for flutter driver

    Autosize text widget doesn't return text value with getText() for flutter driver

    Steps to Reproduce Facing uncaught error exception when flutter driver getText() method is used to retrieve text for automation.

    Code sample Flutter driver initialization:

    driver = new AndroidDriver<MobileElement>(url, cap);
    driver.manage().timeouts().implicitlyWait(sessionTimeout, TimeUnit.SECONDS);
    finder = new FlutterFinder(driver);
    

    getText() method code:

        FlutterElement element = finder.byValueKey(locator);
        return element.getText(); //uncaught exception found here
    

    Details of exception: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Cannot execute command get_text, server reponse { "isError": true, "response": "Uncaught extension error while executing get_text: Unsupported operation: Type AutoSizeText is currently not supported by getText\n#0 CommandHandlerFactory._getText (package:flutter_driver/src/common/handler_factory.dart:418:7)\n<asynchronous suspension>\n#1 FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:372:31)\n<asynchronous suspension>\n#2 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:855:18)\n<asynchronous suspension>\n", "type": "_extensionType", "method": "ext.flutter.driver" }

    Screenshots Screenshot 2022-10-21 at 4 32 07 PM

    Version

    • Flutter version: 3.3.5
    • auto_size_text version: 3.0.0
    • appium version: 2.0.0-beta.44
    bug 
    opened by rajagopalvk 0
  • Update outdated LICENSE year

    Update outdated LICENSE year

    With this update, you won't care about any further license year updates

    Using present instead of the second year is a common pattern, here are some examples

    https://github.com/babel/babel/blob/4fb29a372b18e82ba72262db43b80b220a5cce01/LICENSE#L3 https://github.com/reduxjs/redux/blob/8ad084251a5b3e4617157fc52795b6284e68bc1e/LICENSE.md?plain=1#L3 https://github.com/pmndrs/react-spring/blob/e7d423cde197db9d53a00f96422c6d7f8ce12b29/LICENSE#L3 https://github.com/vercel/styled-jsx/blob/e8245813f9c3e633a9b2d2414fb11e6386b31216/license.md?plain=1#L3 https://github.com/styled-components/styled-components/blob/09929bd9bc05da085206c94679f07597b46212e4/LICENSE#L3

    opened by Serjobas 0
  • AutoSizeText doesn't work on build, only after setState.

    AutoSizeText doesn't work on build, only after setState.

    Steps to Reproduce Hi, I'm using AutoSizeText on web. After build (Refresh page, hot reload, restart etc...) AutoSizeText doesn't resize the text according to the sizes. It does work after doing 'setState' operation.

    What coukd be the reason?

    Thanks.

    Version

    • Flutter version: 3.0.0.
    • auto_size_text version: 3.0.0
    bug 
    opened by burekas7 0
Owner
Simon Leier
Electrical engineer, Android & Flutter developer.
Simon Leier
A Flutter package to parse text and make them into linkified text widget

?? Flutter Parsed text A Flutter package to parse text and extract parts using predefined types like url, phone and email and also supports Regex. Usa

Fayeed Pawaskar 213 Dec 27, 2022
Rich Text renderer that parses Contentful Rich Text JSON object and returns a renderable Flutter widget

Contentful Rich Text Renderer for Flutter Rich Text renderer that parses Contentful Rich Text field JSON output and produces a Flutter Widget tree tha

Kumanu 45 Nov 10, 2022
Arc Text Widget for Flutter

Flutter Arc Text Renders text along the arc. See demo. The story behind the plugin is here. Basic usage class MyApp extends StatelessWidget

Kirill Bubochkin 15 Oct 18, 2021
A masked text for Flutter.

flutter_masked_text Masked text input for flutter. Alert Hi guys! Unfortunately, I'm not developing mobile anymore. This repo will not receive updates

Ben-hur Santos Ott 264 Dec 21, 2022
Soft and gentle rich text editing for Flutter applications.

About Zefyr Soft and gentle rich text editing for Flutter applications. You are viewing early dev preview version of this package which is no longer a

Memspace 2.2k Jan 8, 2023
A simple Flutter package that makes turning a FAB into a text field easy.

flutter_text_field_fab A simple Flutter widget that makes turning a FAB into a text field easy.

Haefele Software 4 Jan 18, 2022
Soft and gentle rich text editing for Flutter applications

Soft and gentle rich text editing for Flutter applications. Zefyrka is a fork of Zefyr package with the following improvements: support Flutter 2.0 op

null 85 Dec 21, 2022
Text Editor in Flutter for Android and iOS to help free write WYSIWYG HTML code

Flutter Summernote Text Editor in Flutter for Android and iOS to help free write WYSIWYG HTML code based on Summernote 0.8.18 javascript wrapper. NOTI

Chandra Abdul Fattah 41 Sep 12, 2022
A Tricky Solution for Implementing Inline-Image-In-Text Feature in Flutter.

A Tricky Solution for Implementing Inline-Image-In-Text Feature in Flutter.

Bytedance Inc. 646 Dec 29, 2022
A customizable code text field supporting syntax highlighting

CodeField A customizable code text field supporting syntax highlighting Live demo A live demo showcasing a few language / themes combinaisons Showcase

Bertrand 162 Dec 23, 2022
Flutter textfield validation lets you validate different textform fields in your Flutter app

Flutter textfield validation lets you validate different textform fields in your Flutter app

World-Package 2 Sep 15, 2022
A markdown renderer for Flutter.

Flutter Markdown A markdown renderer for Flutter. It supports the original format, but no inline HTML. Overview The flutter_markdown package renders M

Flutter 828 Aug 12, 2021
A Flutter Package to render Mathematics, Physics and Chemistry Equations based on LaTeX

flutter_tex Contents About Demo Video Screenshots How to use? Android iOS Web Examples Quick Example TeXView Document TeXView Markdown TeXView Quiz Te

Shahzad Akram 219 Jan 5, 2023
flutter 中文排版,支持分页上下对齐 两端对齐 翻页动画

text_composition flutter 中文排版 分页 上下对齐 两端对齐 多栏布局 弃用richText,使用Canvas,精确定位绘图位置,消除字体对排版影响 视频与截图 demo https://github.com/mabDc/text_composition/releases/t

西红柿大芝麻 50 Nov 3, 2022
Flutter Tutorial - PDF Viewer - Asset, File, Network & Firebase

Flutter Tutorial - PDF Viewer - Asset, File, Network & Firebase Use the Flutter PDF Viewer to download PDF documents and display them within your Flut

Johannes Milke 36 Dec 9, 2022
Create an AutoComplete TextField to search JSON data based on suggestions in Flutter.

Flutter Tutorial - AutoComplete TextField & AutoComplete Search Create an AutoComplete TextField to search JSON data based on suggestions in Flutter.

Johannes Milke 32 Oct 23, 2022
Flutter phone number input

phone_form_field Flutter phone input integrated with flutter internationalization Features Totally cross platform, this is a dart only package / depen

cedvdb 38 Dec 31, 2022
A low code editor with the full power of flutter.

flutter_blossom ?? Low code editor with the full power of flutter. Think in flutter, watch your ideas come to life, plan ahead and let your creativity

Flutter Blossom 0 Dec 2, 2021
A Flutter package provides some implementations of TextInputFormatter that format input with pre-defined patterns

A Flutter package provides some implementations of TextInputFormatter that format input with pre-defined patterns

HungHD 192 Dec 31, 2022