From e12c62735699ca3cbc4966229cfdce0efc170ec0 Mon Sep 17 00:00:00 2001 From: sudhir manandhar Date: Wed, 22 Jan 2025 12:48:20 +0545 Subject: [PATCH 1/4] maxlines in parameter --- lib/src/rounded_background_text_span.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/rounded_background_text_span.dart b/lib/src/rounded_background_text_span.dart index 8890786..8f0af9e 100644 --- a/lib/src/rounded_background_text_span.dart +++ b/lib/src/rounded_background_text_span.dart @@ -23,6 +23,7 @@ class RoundedBackgroundTextSpan extends WidgetSpan { double? innerRadius, double? outerRadius, TextAlign? textAlign, + int? maxLines, }) : super( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), @@ -35,7 +36,7 @@ class RoundedBackgroundTextSpan extends WidgetSpan { innerRadius: innerRadius ?? kDefaultInnerRadius, outerRadius: outerRadius ?? kDefaultOuterRadius, textAlign: textAlign, - maxLines: 1, + maxLines: maxLines ?? 1, ), ), baseline: baseline, From 223512d060bb3ee1f87d5c147721d1071df5cb2a Mon Sep 17 00:00:00 2001 From: sudhir manandhar Date: Wed, 22 Jan 2025 12:53:43 +0545 Subject: [PATCH 2/4] maxlines in parameter --- lib/src/rounded_background_text_span.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/rounded_background_text_span.dart b/lib/src/rounded_background_text_span.dart index 8f0af9e..52affb3 100644 --- a/lib/src/rounded_background_text_span.dart +++ b/lib/src/rounded_background_text_span.dart @@ -36,7 +36,7 @@ class RoundedBackgroundTextSpan extends WidgetSpan { innerRadius: innerRadius ?? kDefaultInnerRadius, outerRadius: outerRadius ?? kDefaultOuterRadius, textAlign: textAlign, - maxLines: maxLines ?? 1, + maxLines: maxLines, ), ), baseline: baseline, From 971921182c89419c40d9f3bd0e02b94833c50fd7 Mon Sep 17 00:00:00 2001 From: sudhir manandhar Date: Wed, 22 Jan 2025 12:59:58 +0545 Subject: [PATCH 3/4] maxlines in parameter --- CHANGELOG.md | 4 +++ example/pubspec.lock | 72 +++++++++++++++++++++++++++++--------------- pubspec.lock | 70 ++++++++++++++++++++++++++++-------------- pubspec.yaml | 2 +- 4 files changed, 100 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbaaad6..364201c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.1 +* fix: Added maxlines on parameters replacing hardcoded maxline + + ## 0.5.0 * fix: Update vertical alignment ([#19](https://github.com/bdlukaa/rounded_background_text/issues/19)) diff --git a/example/pubspec.lock b/example/pubspec.lock index 6a5cfef..4565ea5 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.19.0" fake_async: dependency: transitive description: @@ -67,6 +67,30 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06" + url: "https://pub.dev" + source: hosted + version: "10.0.7" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379" + url: "https://pub.dev" + source: hosted + version: "3.0.8" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" lints: dependency: transitive description: @@ -79,46 +103,46 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.15.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" rounded_background_text: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.4.3" + version: "0.5.1" sky_engine: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_span: dependency: transitive description: @@ -131,10 +155,10 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.12.0" stream_channel: dependency: transitive description: @@ -147,10 +171,10 @@ packages: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" term_glyph: dependency: transitive description: @@ -163,10 +187,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.3" vector_math: dependency: transitive description: @@ -175,14 +199,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "14.3.0" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" - flutter: ">=1.17.0" + dart: ">=3.4.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.lock b/pubspec.lock index 29a37b2..a50b399 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.19.0" fake_async: dependency: transitive description: @@ -67,6 +67,30 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06" + url: "https://pub.dev" + source: hosted + version: "10.0.7" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379" + url: "https://pub.dev" + source: hosted + version: "3.0.8" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" lints: dependency: transitive description: @@ -79,39 +103,39 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.15.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" sky_engine: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_span: dependency: transitive description: @@ -124,10 +148,10 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.12.0" stream_channel: dependency: transitive description: @@ -140,10 +164,10 @@ packages: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" term_glyph: dependency: transitive description: @@ -156,10 +180,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.3" vector_math: dependency: transitive description: @@ -168,14 +192,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "14.3.0" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" - flutter: ">=1.17.0" + dart: ">=3.4.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 7bcb1bc..ea549ed 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: rounded_background_text description: Text, TextField and TextSpan highlighted with rounded corners -version: 0.5.0 +version: 0.5.1 repository: https://github.com/bdlukaa/rounded_background_text environment: From b982e2abc8384fa83b85e7cbb17f877b7a9b97e3 Mon Sep 17 00:00:00 2001 From: sudhir manandhar Date: Wed, 5 Feb 2025 12:13:43 +0545 Subject: [PATCH 4/4] adds: functionality to pass padding --- lib/src/rounded_background_text.dart | 99 ++++++++++++++++------- lib/src/rounded_background_text_span.dart | 10 ++- 2 files changed, 81 insertions(+), 28 deletions(-) diff --git a/lib/src/rounded_background_text.dart b/lib/src/rounded_background_text.dart index 553ac3e..2a8543e 100644 --- a/lib/src/rounded_background_text.dart +++ b/lib/src/rounded_background_text.dart @@ -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), ); }); } @@ -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> computeLines(TextPainter painter) { + static List> 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> 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); 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) { diff --git a/lib/src/rounded_background_text_span.dart b/lib/src/rounded_background_text_span.dart index 52affb3..a78567b 100644 --- a/lib/src/rounded_background_text_span.dart +++ b/lib/src/rounded_background_text_span.dart @@ -24,9 +24,14 @@ class RoundedBackgroundTextSpan extends WidgetSpan { 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, @@ -37,6 +42,9 @@ class RoundedBackgroundTextSpan extends WidgetSpan { outerRadius: outerRadius ?? kDefaultOuterRadius, textAlign: textAlign, maxLines: maxLines, + firstLinePadding: firstLinePadding, + lastLinePadding: lastLinePadding, + innerLinePadding: innerLinePadding, ), ), baseline: baseline,