Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add TextHeightBehavior support #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/src/auto_size_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AutoSizeText extends StatefulWidget {
this.textScaleFactor,
this.maxLines,
this.semanticsLabel,
this.textHeightBehavior,
}) : textSpan = null,
super(key: key);

Expand All @@ -57,6 +58,7 @@ class AutoSizeText extends StatefulWidget {
this.textScaleFactor,
this.maxLines,
this.semanticsLabel,
this.textHeightBehavior,
}) : data = null,
super(key: key);

Expand Down Expand Up @@ -215,6 +217,20 @@ class AutoSizeText extends StatefulWidget {
/// ```
final String? semanticsLabel;

/// Defines how to apply [TextStyle.height] over and under text.
///
/// [TextHeightBehavior.applyHeightToFirstAscent] and
/// [TextHeightBehavior.applyHeightToLastDescent] represent whether the
/// [TextStyle.height] modifier will be applied to the corresponding metric. By
/// default both properties are true, and [TextStyle.height] is applied as
/// normal. When set to false, the font's default ascent will be used.
///
/// [TextHeightBehavior.leadingDistribution] determines how the
/// leading is distributed over and under text. This
/// property applies before [TextHeightBehavior.applyHeightToFirstAscent] and
/// [TextHeightBehavior.applyHeightToLastDescent].
final TextHeightBehavior? textHeightBehavior;

@override
_AutoSizeTextState createState() => _AutoSizeTextState();
}
Expand Down Expand Up @@ -425,6 +441,7 @@ class _AutoSizeTextState extends State<AutoSizeText> {
textScaleFactor: 1,
maxLines: maxLines,
semanticsLabel: widget.semanticsLabel,
textHeightBehavior: widget.textHeightBehavior,
);
} else {
return Text.rich(
Expand All @@ -440,6 +457,7 @@ class _AutoSizeTextState extends State<AutoSizeText> {
textScaleFactor: fontSize / style.fontSize!,
maxLines: maxLines,
semanticsLabel: widget.semanticsLabel,
textHeightBehavior: widget.textHeightBehavior,
);
}
}
Expand Down