-
-
Notifications
You must be signed in to change notification settings - Fork 14
Fixes: Replace hardcoded maxlines to parameter #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
manandharsudhir
wants to merge
4
commits into
bdlukaa:main
Choose a base branch
from
manandharsudhir:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,9 @@ class RoundedBackgroundText extends StatelessWidget { | |||||||||||||||||||||||||||||||
| this.textHeightBehavior, | ||||||||||||||||||||||||||||||||
| this.innerRadius = kDefaultInnerRadius, | ||||||||||||||||||||||||||||||||
| this.outerRadius = kDefaultOuterRadius, | ||||||||||||||||||||||||||||||||
| this.firstLinePadding, | ||||||||||||||||||||||||||||||||
| this.innerLinePadding, | ||||||||||||||||||||||||||||||||
| this.lastLinePadding, | ||||||||||||||||||||||||||||||||
| }) : text = TextSpan(text: text, style: style); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// Creates a rounded background text based on an [InlineSpan], that can have | ||||||||||||||||||||||||||||||||
|
|
@@ -61,9 +64,16 @@ class RoundedBackgroundText extends StatelessWidget { | |||||||||||||||||||||||||||||||
| this.textHeightBehavior, | ||||||||||||||||||||||||||||||||
| this.innerRadius = kDefaultInnerRadius, | ||||||||||||||||||||||||||||||||
| this.outerRadius = kDefaultOuterRadius, | ||||||||||||||||||||||||||||||||
| this.firstLinePadding, | ||||||||||||||||||||||||||||||||
| this.innerLinePadding, | ||||||||||||||||||||||||||||||||
| this.lastLinePadding, | ||||||||||||||||||||||||||||||||
| }) : assert(innerRadius >= 0.0 && innerRadius <= 20.0), | ||||||||||||||||||||||||||||||||
| assert(outerRadius >= 0.0 && outerRadius <= 20.0); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| final EdgeInsets? firstLinePadding; | ||||||||||||||||||||||||||||||||
| final EdgeInsets? innerLinePadding; | ||||||||||||||||||||||||||||||||
| final EdgeInsets? lastLinePadding; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// Creates a selectable [RoundedBackgroundText] | ||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||
| /// See also: | ||||||||||||||||||||||||||||||||
|
|
@@ -286,11 +296,13 @@ class RoundedBackgroundText extends StatelessWidget { | |||||||||||||||||||||||||||||||
| painter.height.clamp(0, constraints.maxHeight), | ||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||
| painter: RoundedBackgroundTextPainter( | ||||||||||||||||||||||||||||||||
| backgroundColor: backgroundColor ?? Colors.transparent, | ||||||||||||||||||||||||||||||||
| text: painter, | ||||||||||||||||||||||||||||||||
| innerRadius: innerRadius, | ||||||||||||||||||||||||||||||||
| outerRadius: outerRadius, | ||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||
| backgroundColor: backgroundColor ?? Colors.transparent, | ||||||||||||||||||||||||||||||||
| text: painter, | ||||||||||||||||||||||||||||||||
| innerRadius: innerRadius, | ||||||||||||||||||||||||||||||||
| outerRadius: outerRadius, | ||||||||||||||||||||||||||||||||
| firstLinePadding: firstLinePadding, | ||||||||||||||||||||||||||||||||
| innerLinePadding: innerLinePadding, | ||||||||||||||||||||||||||||||||
| lastLinePadding: lastLinePadding), | ||||||||||||||||||||||||||||||||
|
Comment on lines
+299
to
+305
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
@@ -302,12 +314,18 @@ class RoundedBackgroundTextPainter extends CustomPainter { | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| final double innerRadius; | ||||||||||||||||||||||||||||||||
| final double outerRadius; | ||||||||||||||||||||||||||||||||
| final EdgeInsets? firstLinePadding; | ||||||||||||||||||||||||||||||||
| final EdgeInsets? innerLinePadding; | ||||||||||||||||||||||||||||||||
| final EdgeInsets? lastLinePadding; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const RoundedBackgroundTextPainter({ | ||||||||||||||||||||||||||||||||
| required this.backgroundColor, | ||||||||||||||||||||||||||||||||
| required this.text, | ||||||||||||||||||||||||||||||||
| required this.innerRadius, | ||||||||||||||||||||||||||||||||
| required this.outerRadius, | ||||||||||||||||||||||||||||||||
| this.firstLinePadding, | ||||||||||||||||||||||||||||||||
| this.innerLinePadding, | ||||||||||||||||||||||||||||||||
| this.lastLinePadding, | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @visibleForTesting | ||||||||||||||||||||||||||||||||
|
|
@@ -322,11 +340,22 @@ class RoundedBackgroundTextPainter extends CustomPainter { | |||||||||||||||||||||||||||||||
| /// painter.layout(); | ||||||||||||||||||||||||||||||||
| /// final lines = RoundedBackgroundTextPainter.computeLines(painter); | ||||||||||||||||||||||||||||||||
| /// ``` | ||||||||||||||||||||||||||||||||
| static List<List<LineMetricsHelper>> computeLines(TextPainter painter) { | ||||||||||||||||||||||||||||||||
| static List<List<LineMetricsHelper>> computeLines( | ||||||||||||||||||||||||||||||||
| TextPainter painter, { | ||||||||||||||||||||||||||||||||
| EdgeInsets? firstLinePadding, | ||||||||||||||||||||||||||||||||
| EdgeInsets? innerLinePadding, | ||||||||||||||||||||||||||||||||
| EdgeInsets? lastLinePadding, | ||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||
| final metrics = painter.computeLineMetrics(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| final helpers = metrics.map((lineMetric) { | ||||||||||||||||||||||||||||||||
| return LineMetricsHelper(lineMetric, metrics.length); | ||||||||||||||||||||||||||||||||
| return LineMetricsHelper( | ||||||||||||||||||||||||||||||||
| lineMetric, | ||||||||||||||||||||||||||||||||
| metrics.length, | ||||||||||||||||||||||||||||||||
| firstLinePadding: firstLinePadding, | ||||||||||||||||||||||||||||||||
| innerLinePadding: innerLinePadding, | ||||||||||||||||||||||||||||||||
| lastLinePadding: lastLinePadding, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| final List<List<LineMetricsHelper>> lineInfos = [[]]; | ||||||||||||||||||||||||||||||||
|
|
@@ -344,7 +373,10 @@ class RoundedBackgroundTextPainter extends CustomPainter { | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||
| void paint(Canvas canvas, Size size) { | ||||||||||||||||||||||||||||||||
| final lineInfos = computeLines(text); | ||||||||||||||||||||||||||||||||
| final lineInfos = computeLines(text, | ||||||||||||||||||||||||||||||||
| firstLinePadding: firstLinePadding, | ||||||||||||||||||||||||||||||||
| innerLinePadding: innerLinePadding, | ||||||||||||||||||||||||||||||||
| lastLinePadding: lastLinePadding); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+376
to
+379
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve formatting:
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for (final lineInfo in lineInfos) { | ||||||||||||||||||||||||||||||||
| paintBackground(canvas, lineInfo); | ||||||||||||||||||||||||||||||||
|
|
@@ -642,7 +674,13 @@ class LineMetricsHelper { | |||||||||||||||||||||||||||||||
| double? _overridenX; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// Creates a new line metrics helper | ||||||||||||||||||||||||||||||||
| LineMetricsHelper(this.metrics, this.length); | ||||||||||||||||||||||||||||||||
| LineMetricsHelper( | ||||||||||||||||||||||||||||||||
| this.metrics, | ||||||||||||||||||||||||||||||||
| this.length, { | ||||||||||||||||||||||||||||||||
| this.firstLinePadding, | ||||||||||||||||||||||||||||||||
| this.innerLinePadding, | ||||||||||||||||||||||||||||||||
| this.lastLinePadding, | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// Whether this line has no content | ||||||||||||||||||||||||||||||||
| bool get isEmpty => rawWidth == 0.0; | ||||||||||||||||||||||||||||||||
|
|
@@ -653,25 +691,32 @@ class LineMetricsHelper { | |||||||||||||||||||||||||||||||
| /// Whether this line is the last line in the paragraph | ||||||||||||||||||||||||||||||||
| bool get isLast => metrics.lineNumber == length - 1; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| final EdgeInsets? firstLinePadding; | ||||||||||||||||||||||||||||||||
| final EdgeInsets? innerLinePadding; | ||||||||||||||||||||||||||||||||
| final EdgeInsets? lastLinePadding; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| static const _horizontalPaddingFactor = 0.3; | ||||||||||||||||||||||||||||||||
| late final EdgeInsets _firstLinePadding = EdgeInsets.only( | ||||||||||||||||||||||||||||||||
| left: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| right: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| top: height * 0.3, | ||||||||||||||||||||||||||||||||
| bottom: height * 0.175 / 2, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| late final EdgeInsets _innerLinePadding = EdgeInsets.only( | ||||||||||||||||||||||||||||||||
| left: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| right: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| top: 0.0, | ||||||||||||||||||||||||||||||||
| bottom: height * 0.175 / 2, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| late final EdgeInsets _lastLinePadding = EdgeInsets.only( | ||||||||||||||||||||||||||||||||
| left: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| right: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| top: 0.0, | ||||||||||||||||||||||||||||||||
| bottom: height * 0.175 / 2, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| late final EdgeInsets _firstLinePadding = firstLinePadding ?? | ||||||||||||||||||||||||||||||||
| EdgeInsets.only( | ||||||||||||||||||||||||||||||||
| left: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| right: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| top: height * 0.3, | ||||||||||||||||||||||||||||||||
| bottom: height * 0.175 / 2, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| late final EdgeInsets _innerLinePadding = innerLinePadding ?? | ||||||||||||||||||||||||||||||||
| EdgeInsets.only( | ||||||||||||||||||||||||||||||||
| left: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| right: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| top: 0.0, | ||||||||||||||||||||||||||||||||
| bottom: height * 0.175 / 2, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| late final EdgeInsets _lastLinePadding = lastLinePadding ?? | ||||||||||||||||||||||||||||||||
| EdgeInsets.only( | ||||||||||||||||||||||||||||||||
| left: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| right: height * _horizontalPaddingFactor, | ||||||||||||||||||||||||||||||||
| top: 0.0, | ||||||||||||||||||||||||||||||||
| bottom: height * 0.175 / 2, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// Dynamically calculate the outer factor based on the provided [outerRadius] | ||||||||||||||||||||||||||||||||
| double outerRadius(double outerRadius) { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,9 +23,15 @@ class RoundedBackgroundTextSpan extends WidgetSpan { | |||||
| double? innerRadius, | ||||||
| double? outerRadius, | ||||||
| TextAlign? textAlign, | ||||||
| int? maxLines, | ||||||
| EdgeInsets? firstLinePadding, | ||||||
| EdgeInsets? innerLinePadding, | ||||||
| EdgeInsets? lastLinePadding, | ||||||
| EdgeInsets? outerPadding, | ||||||
| }) : super( | ||||||
| child: Padding( | ||||||
| padding: const EdgeInsets.symmetric(horizontal: 8.0), | ||||||
| padding: | ||||||
| outerPadding ?? const EdgeInsets.symmetric(horizontal: 8.0), | ||||||
| child: RoundedBackgroundText( | ||||||
| text, | ||||||
| style: style, | ||||||
|
|
@@ -35,7 +41,10 @@ class RoundedBackgroundTextSpan extends WidgetSpan { | |||||
| innerRadius: innerRadius ?? kDefaultInnerRadius, | ||||||
| outerRadius: outerRadius ?? kDefaultOuterRadius, | ||||||
| textAlign: textAlign, | ||||||
| maxLines: 1, | ||||||
| maxLines: maxLines, | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| firstLinePadding: firstLinePadding, | ||||||
| lastLinePadding: lastLinePadding, | ||||||
| innerLinePadding: innerLinePadding, | ||||||
| ), | ||||||
| ), | ||||||
| baseline: baseline, | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.