ResponsiveText class
A responsive text widget that automatically adapts its content and size based on the available space and screen type.
Features:
- Auto-resize: Shrinks font size to fit available width (binary search).
- Short text: Shows abbreviated text on small screens.
- Overflow protection: Never overflows — guaranteed.
Example
ResponsiveText(
'Welcome to our Amazing App',
shortText: 'Welcome',
style: TextStyle(fontSize: 18.fz),
autoResize: true,
minFontSize: 10,
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- ResponsiveText
Constructors
- ResponsiveText(String text, {Key? key, String? shortText, TextStyle? style, bool autoResize = false, double minFontSize = 8.0, double stepGranularity = 0.5, int? maxLines, TextAlign? textAlign, TextOverflow overflow = TextOverflow.ellipsis, TextDirection? textDirection, String? semanticsLabel})
-
Creates a ResponsiveText widget.
const
Properties
- autoResize → bool
-
Whether to automatically shrink the font to fit available width.
Defaults to
falsefor maximum performance (no LayoutBuilder).final - hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- maxLines → int?
-
Maximum number of lines. Defaults to
null(unlimited).final - minFontSize → double
-
The minimum font size when autoResize is true. Defaults to
8.0.final - overflow → TextOverflow
-
Overflow behavior when autoResize is false. Defaults to TextOverflow.ellipsis.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticsLabel → String?
-
Semantic label for accessibility.
final
- shortText → String?
-
Optional shorter text for small screens (watch/mobile).
If null, the full text is always used.
final
- stepGranularity → double
-
The step size for font size reduction during auto-resize.
Smaller values = more precise fit but slightly more computation.
Defaults to
0.5.final - style → TextStyle?
-
The text style. If null, uses the default from DefaultTextStyle.
final
- text → String
-
The full text to display.
final
- textAlign → TextAlign?
-
Text alignment. Defaults to TextAlign.start.
final
- textDirection → TextDirection?
-
Text direction for RTL support.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited