11import 'dart:math' ;
22
33import 'package:flutter/widgets.dart' ;
4- import 'package:unicode_emojis/unicode_emojis.dart' ;
54
65const String _kLowerAlphabet = 'abcdefghijklmnopqrstuvwxyz ' ;
76const String _kUpperAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ;
87const String _kNumbers = '0123456789' ;
98const String _kSymbols = '`~!@#\$ %^&*()-_=+[{]}\\ |;:\' ",<.>/?' ;
109const String _kSpace = ' ' ;
1110const String _kZeroWidth = '' ;
12- final String _allEmojis =
13- UnicodeEmojis .allEmojis.map ((emoji) => emoji.emoji).join ('' );
1411
1512extension _StringHelper on String {
1613 bool isSymbol () => _kSymbols.contains (this );
@@ -24,8 +21,18 @@ extension _StringHelper on String {
2421 bool isLowerAlphabet () => _kLowerAlphabet.contains (this );
2522
2623 bool isUpperAlphabet () => _kUpperAlphabet.contains (this );
24+ }
25+
26+ /// A builder that constructs a tape of characters tailored for a specific
27+ /// condition of characters such as emojis.
28+ abstract class CharacterTapeBuilder {
29+ /// The characters that are used to build the tape of characters. For example,
30+ /// an entire emoji set.
31+ String get characters;
2732
28- bool isEmoji () => _allEmojis.contains (this );
33+ /// Compares two strings to determine if the builder should be used to
34+ /// insert the [characters] into the main tape.
35+ bool compare (String a, String b);
2936}
3037
3138/// Defines the strategy to create the tape of character symbols
@@ -38,9 +45,17 @@ sealed class SymbolTapeStrategy {
3845 /// be rendered and animated to roll twice instead of just once.
3946 final bool repeatCharacters;
4047
48+ /// A set of [CharacterTapeBuilder] s that can be used to build the tape
49+ /// of characters to interpolate to and from for a specific set of characters,
50+ /// like emojis.
51+ final Set <CharacterTapeBuilder > characterTapeBuilders;
52+
4153 /// Creates a new [SymbolTapeStrategy] with the given [repeatCharacters]
4254 /// property.
43- const SymbolTapeStrategy ([this .repeatCharacters = true ]);
55+ const SymbolTapeStrategy ({
56+ this .repeatCharacters = true ,
57+ this .characterTapeBuilders = const {},
58+ });
4459
4560 /// Builds the tape of characters to interpolate to and from.
4661 String build (String a, String b) =>
@@ -68,8 +83,10 @@ sealed class SymbolTapeStrategy {
6883 if (a.isNumber () || b.isNumber ()) {
6984 charKitBuffer.write (_kNumbers);
7085 }
71- if (a.isEmoji () || b.isEmoji ()) {
72- charKitBuffer.write (_allEmojis);
86+ for (final CharacterTapeBuilder builder in characterTapeBuilders) {
87+ if (builder.compare (a, b)) {
88+ charKitBuffer.write (builder.characters);
89+ }
7390 }
7491 }
7592
@@ -107,8 +124,10 @@ sealed class SymbolTapeStrategy {
107124 if (a.isNumber () || b.isNumber ()) {
108125 charKitBuffer.write (_kNumbers);
109126 }
110- if (a.isEmoji () || b.isEmoji ()) {
111- charKitBuffer.write (_allEmojis);
127+ for (final CharacterTapeBuilder builder in characterTapeBuilders) {
128+ if (builder.compare (a, b)) {
129+ charKitBuffer.write (builder.characters);
130+ }
112131 }
113132 }
114133
@@ -137,7 +156,7 @@ sealed class SymbolTapeStrategy {
137156class AllSymbolsTapeStrategy extends SymbolTapeStrategy {
138157 /// Creates a new [AllSymbolsTapeStrategy] with the given [repeatCharacters]
139158 /// property.
140- const AllSymbolsTapeStrategy ([ super .repeatCharacters = true ] );
159+ const AllSymbolsTapeStrategy ({ super .repeatCharacters = true } );
141160}
142161
143162/// Constructs symbol tapes that contain all the characters
@@ -167,9 +186,11 @@ class ConsistentSymbolTapeStrategy extends SymbolTapeStrategy {
167186
168187 /// Creates a new [ConsistentSymbolTapeStrategy] with the given [distance]
169188 /// and [repeatCharacters] properties.
170- const ConsistentSymbolTapeStrategy (this .distance,
171- [super .repeatCharacters = true ])
172- : assert (
189+ const ConsistentSymbolTapeStrategy (
190+ this .distance, {
191+ super .repeatCharacters = true ,
192+ Set <CharacterTapeBuilder > characterTapeBuilders = const {},
193+ }) : assert (
173194 distance >= 0 ,
174195 'Distance must be >= 0.' ,
175196 );
0 commit comments