Skip to content

Commit

Permalink
Test: Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rkishan516 committed Dec 7, 2024
1 parent 0dbeb11 commit 556217a
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 27 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## 1.1.0

* test: Add test cases
* feat: Mark default text style optional
* docs: Update usage with image

## 1.0.0

* Update default richTextSperator to #
* feat: Update default richTextSperator to #
* fix: Update flutter lints to v5

## 0.1.0
Expand Down
25 changes: 3 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ FlexibleText is a Flutter widget that allows you to seamlessly mix and match ric
<img src="https://img.shields.io/pub/popularity/flexible_text.svg?style=for-the-badge&color=c05600&label=Popularity&labelColor=black"/>
</a>

![title](assets/usage.webp)


### Features

- Rich Text Segments: Use different styles and gestures for various parts of your text.
Expand All @@ -41,28 +44,6 @@ Import the Package
import 'package:flexible_text/flexible_text.dart';
```

#### Usage 📝

```dart
FlexibleText(
text: 'Hello #World#~1~~star~',
style: TextStyle(color: Colors.black),
richStyles: [TextStyle(color: Colors.red)],
textRecognizers: [TapGestureRecognizer()..onTap = () { print('World tapped'); }],
namedWidgets: {'star': Icon(Icons.star_border)},
widgets: [Icon(Icons.star)],
);
```

In this example:

- #World# will be styled with TextStyle(color: Colors.red) and will have a tap gesture.
- \~1\~ will be replaced by an Icon(Icons.star).
- \~star\~ will be replaced by an Icon(Icons.star_border).

and result to

$${\color{black}Hello \space \color{red}World \space \color{black}★☆}$$

#### Customization Options 🎨

Expand Down
Binary file added assets/usage.webp
Binary file not shown.
6 changes: 3 additions & 3 deletions lib/flexible_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FlexibleText extends StatelessWidget {
const FlexibleText({
super.key,
required this.text,
required this.style,
this.style,
this.richStyles,
this.textRecognizers,
this.textAlign,
Expand All @@ -42,7 +42,7 @@ class FlexibleText extends StatelessWidget {
final String text;

/// The default text style to be applied to the text.
final TextStyle style;
final TextStyle? style;

/// A list of styles to be applied to rich text segments.
final List<TextStyle?>? richStyles;
Expand Down Expand Up @@ -145,7 +145,7 @@ class FlexibleText extends StatelessWidget {
currentChunk = currentCheckingCharacter;
} else {
var widgetIndex = int.tryParse(text.substring(i + 1, end));
if (widgetIndex != null) {
if (widgetIndex != null && widgetIndex - 1 < widgets.length) {
var tmpText = text.substring(i + 1, end);
blocks.add(
_WidgetBlock(text: tmpText, child: widgets[widgetIndex - 1]));
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flexible_text
description: Powerful and flexible solution to create dynamic, interactive and customizable text with widgets, allows to write a single text block to show anything you want.
version: 1.0.0
version: 1.1.0
homepage: https://github.com/rkishan516/flexible_text
repository: https://github.com/rkishan516/flexible_text
topics: [widgets, flexible, text, styling, rich]
Expand Down
Loading

0 comments on commit 556217a

Please sign in to comment.