Skip to content

Commit 08a3e21

Browse files
committed
update to v 0.0.4
1 parent 0f4f890 commit 08a3e21

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.4
2+
3+
* Add `correctCharProbability` and `scrambleCycles` parameters
4+
15
## 0.0.3
26

37
* Add [Medium article](https://medium.com/@khlebobul/scramble-effect-for-text-flutter-widget-d92df44dd7a8)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ TextScramble(
1616
text: 'Hello World!',
1717
speed: Duration(milliseconds: 30),
1818
chars: '!<>-_\\/[]{}—=+*^?#________',
19+
correctCharProbability = 0.1, // Correct character probability in [0, 1]
20+
scrambleCycles = 4, // Number of times to scramble the text
1921
style: TextStyle(
2022
fontSize: 40,
2123
color: Colors.black,

example/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class MainApp extends StatelessWidget {
1919
text: 'Hello World!',
2020
speed: Duration(milliseconds: 50),
2121
chars: '!<>-_\\/[]{}—=+*^?#________',
22+
correctCharProbability = 0.1, // Correct character probability in [0, 1]
23+
scrambleCycles = 4, // Number of times to scramble the text
2224
style: TextStyle(
2325
fontSize: 40,
2426
color: Colors.green,

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ environment:
99
dependencies:
1010
flutter:
1111
sdk: flutter
12-
use_scramble: ^0.0.1
12+
use_scramble: ^0.0.4
1313

1414
dev_dependencies:
1515
flutter_test:

lib/src/text_scramble.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ class TextScramble extends StatefulWidget {
77
final Duration speed;
88
final String chars;
99
final TextStyle? style;
10+
final double correctCharProbability; // Correct character probability in [0, 1]
11+
final int scrambleCycles; // Number of times to scramble the text
1012

1113
const TextScramble({
1214
super.key,
1315
required this.text,
1416
this.speed = const Duration(milliseconds: 50),
1517
this.chars = '!<>-_\\/[]{}—=+*^?#________',
1618
this.style,
19+
this.correctCharProbability = 0.1,
20+
this.scrambleCycles = 4,
1721
});
1822

1923
@override
@@ -38,7 +42,7 @@ class _TextScrambleState extends State<TextScramble> {
3842
int counter = 0;
3943
_timer = Timer.periodic(widget.speed, (timer) {
4044
// Check if it's time to end the animation
41-
if (counter >= widget.text.length * 4) {
45+
if (counter >= widget.text.length * widget.scrambleCycles) {
4246
timer.cancel();
4347
setState(() {
4448
_displayText = widget.text;
@@ -52,7 +56,7 @@ class _TextScrambleState extends State<TextScramble> {
5256
if (_done[index]) return widget.text[index];
5357

5458
// With a 10% probability, set the correct character
55-
if (_random.nextDouble() < 0.1) {
59+
if (_random.nextDouble() < widget.correctCharProbability) {
5660
_done[index] = true;
5761
return widget.text[index];
5862
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: use_scramble
22
description: "Lightweight package for random text animations inspired by useScramble"
3-
version: 0.0.3
3+
version: 0.0.4
44
homepage: https://github.com/khlebobul/use_scramble
55

66
environment:

0 commit comments

Comments
 (0)