{"id":13552509,"url":"https://github.com/simc/auto_size_text","last_synced_at":"2025-10-23T02:40:31.061Z","repository":{"id":40680534,"uuid":"149683226","full_name":"simc/auto_size_text","owner":"simc","description":"Flutter widget that automatically resizes text to fit perfectly within its bounds.","archived":false,"fork":false,"pushed_at":"2023-12-07T14:28:29.000Z","size":6085,"stargazers_count":2084,"open_issues_count":95,"forks_count":246,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-04-14T19:58:56.576Z","etag":null,"topics":["android","flutter","ios","text"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/auto_size_text","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"custom":"paypal.me/simonleier"}},"created_at":"2018-09-20T23:37:35.000Z","updated_at":"2025-04-09T01:15:36.000Z","dependencies_parsed_at":"2023-12-12T07:26:42.485Z","dependency_job_id":"2e244c21-51bc-4819-b5eb-f45e63c04e29","html_url":"https://github.com/simc/auto_size_text","commit_stats":null,"previous_names":["leisim/auto_size_text"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simc%2Fauto_size_text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simc%2Fauto_size_text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simc%2Fauto_size_text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simc%2Fauto_size_text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simc","download_url":"https://codeload.github.com/simc/auto_size_text/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328385,"owners_count":22052632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","flutter","ios","text"],"created_at":"2024-08-01T12:02:05.286Z","updated_at":"2025-10-23T02:40:31.009Z","avatar_url":"https://github.com/simc.png","language":"Dart","readme":"# AutoSizeText\n\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/leisim/auto_size_text/CI) [![codecov](https://codecov.io/gh/leisim/auto_size_text/branch/master/graph/badge.svg)](https://codecov.io/gh/leisim/auto_size_text) [![Version](https://img.shields.io/pub/v/auto_size_text.svg)](https://pub.dev/packages/auto_size_text) ![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)\n\nFlutter widget that automatically resizes text to fit perfectly within its bounds.\n\n**Show some ❤️ and star the repo to support the project**\n\n### Resources:\n- [Documentation](https://pub.dev/documentation/auto_size_text/latest/auto_size_text/AutoSizeText-class.html)\n- [Pub Package](https://pub.dev/packages/auto_size_text)\n- [GitHub Repository](https://github.com/leisim/auto_size_text)\n- [Online Demo](https://appetize.io/app/w352kxbnz51c6pfvxrdvxcb3xw?device=nexus5\u0026scale=100\u0026orientation=landscape\u0026osVersion=8.1\u0026deviceColor=black)\n\nAlso check out the blazing fast key-value store [hive](https://github.com/leisim/hive).\n\n\n![](https://raw.githubusercontent.com/leisim/auto_size_text/master/.github/art/maxlines.gif)\n\n## Contents\n\n- [Usage](#usage)\n  - [maxLines](#maxlines)\n  - [minFontSize \u0026 maxFontSize](#minfontsize--maxfontsize)\n  - [group](#group)\n  - [stepGranularity](#stepgranularity)\n  - [presetFontSizes](#presetfontsizes)\n  - [overflowReplacement](#overflowreplacement)\n- [Rich Text](#rich-text)\n- [Parameters](#parameters)\n- [Performance](#performance)\n- [Troubleshooting](#roubleshooting)\n  - [Missing bounds](#missing-bounds)\n  - [MinFontSize too large](#minfontsize-too-large)\n\n\n## Usage\n\n`AutoSizeText` behaves exactly like a `Text`. The only difference is that it resizes text to fit within its bounds.\n\n```dart\nAutoSizeText(\n  'The text to display',\n  style: TextStyle(fontSize: 20),\n  maxLines: 2,\n)\n```\n**Note:** `AutoSizeText` needs bounded constraints to resize the text. More info [here](#troubleshooting).\n\n### maxLines\n\nThe `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.\n\n```dart\nAutoSizeText(\n  'A really long String',\n  style: TextStyle(fontSize: 30),\n  maxLines: 2,\n)\n```\n\n*Sample above*\n\n\n### minFontSize \u0026 maxFontSize\n\nThe `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.\n\nWith `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`.\n\n`maxFontSize` sets the largest possible font size. This is useful if the `TextStyle` inherits the font size and you want to constrain it.\n\n```dart\nAutoSizeText(\n  'A really long String',\n  style: TextStyle(fontSize: 30),\n  minFontSize: 18,\n  maxLines: 4,\n  overflow: TextOverflow.ellipsis,\n)\n```\n\n![](https://raw.githubusercontent.com/leisim/auto_size_text/master/.github/art/minfontsize.gif)\n\n\n### group\n\nYou 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.\n\n**Note:** If a `AutoSizeText` cannot adjust because of constraints like `minFontSize`, it won't have the same size as the other group members.\n\nAn 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.\n\n**Important:** Please don't pass a new instance of `AutoSizeGroup` every build. In other words, save the `AutoSizeGroup` instance in a `StatefulWidget`, or use `AutoSizeGroupBuilder`.\n\n```dart\nvar myGroup = AutoSizeGroup();\n\nAutoSizeText(\n  'Text 1',\n  group: myGroup,\n);\n\nAutoSizeText(\n  'Text 2',\n  group: myGroup,\n);\n```\n\n![](https://raw.githubusercontent.com/leisim/auto_size_text/master/.github/art/group.gif)\n\n\n### stepGranularity\n\nThe `AutoSizeText` will try each font size, starting with `TextStyle.fontSize` until the text fits within its bounds.  \n`stepGranularity` specifies how much the font size is decreased each step. Usually, this value should not be below `1` for best performance.\n\n```dart\nAutoSizeText(\n  'A really long String',\n  style: TextStyle(fontSize: 40),\n  minFontSize: 10,\n  stepGranularity: 10,\n  maxLines: 4,\n  overflow: TextOverflow.ellipsis,\n)\n```\n\n![](https://raw.githubusercontent.com/leisim/auto_size_text/master/.github/art/stepgranularity.gif)\n\n\n### presetFontSizes\n\nIf you want to allow only specific font sizes, you can set them with `presetFontSizes`.\nIf `presetFontSizes` is set, `minFontSize`, `maxFontSize` and `stepGranularity` will be ignored.\n\n```dart\nAutoSizeText(\n  'A really long String',\n  presetFontSizes: [40, 20, 14],\n  maxLines: 4,\n)\n```\n\n![](https://raw.githubusercontent.com/leisim/auto_size_text/master/.github/art/presetfontsizes.gif)\n\n\n### overflowReplacement\n\nIf 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.\n\n```dart\nAutoSizeText(\n  'A String tool long to display without extreme scaling or overflow.',\n  maxLines: 1,\n  overflowReplacement: Text('Sorry String too long'),\n)\n```\n\n![](https://raw.githubusercontent.com/leisim/auto_size_text/master/.github/art/overflowreplacement.gif)\n\n\n## Rich Text\n\nYou can also use Rich Text (like different text styles or links) with `AutoSizeText`. Just use the `AutoSizeText.rich()` constructor\n(which works exactly like the `Text.rich()` constructor).\n\nThe only thing you have to be aware of is how the font size calculation works: The `fontSize` in the `style`\nparameter of `AutoSizeText` (or the inherited `fontSize` if none is set) is used as reference.  \n\nFor example:\n```dart\nAutoSizeText.rich(\n  TextSpan(text: 'A really long String'),\n  style: TextStyle(fontSize: 20),\n  minFontSize: 5,\n)\n```\nThe text will be at least 1/4 of its original size (5 / 20 = 1/4).  \nBut it does not mean that all `TextSpan`s have at least font size `5`.\n\n![](https://raw.githubusercontent.com/leisim/auto_size_text/master/.github/art/maxlines_rich.gif)\n\n\n## Parameters\n\n| Parameter | Description |\n|---|---|\n| `key`* | Controls how one widget replaces another widget in the tree. |\n| `textKey` | Sets the key for the resulting `Text` widget |\n| `style`* | If non-null, the style to use for this text |\n| `minFontSize` | The **minimum** text size constraint to be used when auto-sizing text. \u003cbr\u003e*Is being ignored if `presetFontSizes` is set.*  |\n| `maxFontSize` | The **maximum** text size constraint to be used when auto-sizing text. \u003cbr\u003e*Is being ignored if `presetFontSizes` is set.* |\n| `stepGranularity` | The step size in which the font size is being adapted to constraints. |\n| `presetFontSizes` | Predefines all the possible font sizes.\u003cbr\u003e **Important:** `presetFontSizes` have to be in descending order.  |\n| `group` | Synchronizes the size of multiple `AutoSizeText`s |\n| `textAlign`* | How the text should be aligned horizontally. |\n| `textDirection`* | The directionality of the text. This decides how `textAlign` values like `TextAlign.start` and `TextAlign.end` are interpreted. |\n| `locale`* |  Used to select a font when the same Unicode character can be rendered differently, depending on the locale. |\n| `softWrap`* | Whether the text should break at soft line breaks. |\n| `wrapWords` | Whether words which don't fit in one line should be wrapped. *Defaults to `true` to behave like `Text`.* |\n| `overflow`* | How visual overflow should be handled. |\n| `overflowReplacement` | If the text is overflowing and does not fit its bounds, this widget is displayed instead. |\n| `textScaleFactor`* | The number of font pixels for each logical pixel. Also affects `minFontSize`, `maxFontSize` and `presetFontSizes`. |\n| `maxLines` | An optional maximum number of lines for the text to span. |\n| `semanticsLabel`* | An alternative semantics label for this text. |\n\nParameters marked with \\* behave exactly the same as in `Text`\n\n\n## Performance\n\n`AutoSizeText` is really fast. In fact, you can replace all your `Text` widgets with `AutoSizeText`.\u003cbr\u003e\nNevertheless 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`.\n\nIf your font size has a very large range, consider increasing `stepGranularity`.\n\n\n## Troubleshooting\n\n### Missing bounds\n\nIf `AutoSizeText` overflows or does not resize the text, you should check if it has constrained width and height.\n\n**Wrong** code:\n```dart\nRow(\n  children: \u003cWidget\u003e[\n    AutoSizeText(\n      'Here is a very long text, which should be resized',\n      maxLines: 1,\n    ),\n  ],\n)\n```\nBecause `Row` and other widgets like `Container`, `Column` or `ListView` do not constrain their children, the text will overflow.  \nYou 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).\n\n**Correct** code:\n```dart\nRow(\n  children: \u003cWidget\u003e[\n    Expanded( // Constrains AutoSizeText to the width of the Row\n      child: AutoSizeText(\n        'Here is a very long text, which should be resized',\n        maxLines: 1,\n      )\n    ),\n  ],\n)\n}\n```\n\nFurther explanation can be found [here](https://stackoverflow.com/a/53908204). If you still have problems, please [open an issue](https://github.com/leisim/auto_size_text/issues/new).\n\n\n### MinFontSize too large\n\n`AutoSizeText` does not resize text below the `minFontSize` which defaults to 12. This can happen very easily if you use `AutoSizeText.rich()`:\n\n**Wrong** code:\n```dart\nAutoSizeText.rich(\n  TextSpan(\n    text: 'Text that will not be resized correctly in some cases',\n    style: TextStyle(fontSize: 200),\n  ),\n)\n```\nThis 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 -\u003e 12). Just set `minFontSize = 0` or add `style: TextStyle(fontSize: 200)` to the `AutoSizeText`.\n\n**Note:** If you use the first option, you should also consider lowering `stepGranularity`. Otherwise the steps of resizing will be very large.\n\n**Correct** code:\n```dart\nAutoSizeText.rich(\n  TextSpan(\n    text: 'Text that will be resized correctly',\n    style: TextStyle(fontSize: 200),\n  ),\n  minFontSize: 0,\n  stepGranularity: 0.1,\n)\n```\n\n## MIT License\n```\nCopyright (c) 2018 Simon Leier\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the 'Software'), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","funding_links":["paypal.me/simonleier"],"categories":["Dart"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimc%2Fauto_size_text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimc%2Fauto_size_text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimc%2Fauto_size_text/lists"}