Flutter widget that automatically sets the number of lines to be shown on a text with the ellipsis overflow type.
Show some 💙 and star the repo to support the project
Inspired and based on the AutoSizeText package.
EllipsisOverflowText behaves exactly like a
Text. The only difference is that it automatically sets the number of lines to be shown on a text with the ellipsis overflow type.
EllipsisOverflowText( 'Some text here', style: TextStyle(fontSize: 22), )
Showing ellipsis on break line overflow
For showing an ellipsis overflow when the last rendered text line ends with a break line, you can set the
showEllipsisOnBreakLineOverflow property to
EllipsisOverflowText( 'First String here\n' 'This String will fit the given bounds.', style: TextStyle(fontSize: 22), )
showEllipsisOnBreakLineOverflow equals to
EllipsisOverflowText( 'First String here\n' 'This String will fit the given bounds.', showEllipsisOnBreakLineOverflow: true, ),
||The String text to be shown.|
||Controls how one widget replaces another widget in the tree.|
||The inner Text Widget key.|
||Used to select a font when the same Unicode character can be rendered differently, depending on the locale.|
||An optional maximum number of lines for the text to span.|
||An alternative semantics label for this text.|
||The color to use when painting the selection.|
||Whether the text should break at soft line breaks.|
||Defines the strut, which sets the minimum height a line can be relative to the baseline.|
||If non-null, the style to use for this text|
||How the text should be aligned horizontally.|
||The directionality of the text. This decides how
||Defines how to apply
||The number of font pixels for each logical pixel.|
||The different ways of measuring the width of one or more lines of text.|
||Whether the last rendered text line should ends with ellipsis overflow when the last character is a breakline, i.e. "\n".|
Parameters marked with * behave exactly the same as in
EllipsisOverflowText is really fast. In fact, you can replace all your
Text widgets with
EllipsisOverflowText overflows or does not replace the text with ellipsis characters, you should check if it has constrained width and height.
Row( children: <Widget>[ EllipsisOverflowText( 'Here is a very long text, which will use ellipsis in case the text overflows', ), ], )
Row and other widgets like
ListView do not constrain their children, the text will overflow.
You can fix this by constraining the
EllipsisOverflowText. Wrap it with
Expanded in case of
Column or use a
SizedBox or another widget with fixed width (and height).
Row( children: <Widget>[ Expanded( // Constrains EllipsisOverflowText to the width of the Row (You could use Flexible instead). child: EllipsisOverflowText( 'Here is a very long text, which will use ellipsis in case the text overflows', ) ), ], ) }
Copyright (c) 2022 Vitor Lucas (Reiko-Dev) 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.
- Flutter widget that automatically sets the number of lines to be shown on a text with the Ellipsis text overflow type.