Skip to content

Commit 8479e9c

Browse files
author
Sandip Pramanik
authored
fix: use characters api to render unicode (#15)
* fix: use characters api to render unicode * docs: fix pana docs warnings * docs(example): update the example to have unicode characters * fix: dart formatting
1 parent 9145dac commit 8479e9c

File tree

8 files changed

+49
-16
lines changed

8 files changed

+49
-16
lines changed

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>11.0</string>
24+
<string>12.0</string>
2525
</dict>
2626
</plist>

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
isa = PBXProject;
170170
attributes = {
171171
BuildIndependentTargetsInParallel = YES;
172-
LastUpgradeCheck = 1430;
172+
LastUpgradeCheck = 1510;
173173
ORGANIZATIONNAME = "";
174174
TargetAttributes = {
175175
331C8080294A63A400263BE5 = {
@@ -345,7 +345,7 @@
345345
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
346346
GCC_WARN_UNUSED_FUNCTION = YES;
347347
GCC_WARN_UNUSED_VARIABLE = YES;
348-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
348+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
349349
MTL_ENABLE_DEBUG_INFO = NO;
350350
SDKROOT = iphoneos;
351351
SUPPORTED_PLATFORMS = iphoneos;
@@ -472,7 +472,7 @@
472472
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
473473
GCC_WARN_UNUSED_FUNCTION = YES;
474474
GCC_WARN_UNUSED_VARIABLE = YES;
475-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
475+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
476476
MTL_ENABLE_DEBUG_INFO = YES;
477477
ONLY_ACTIVE_ARCH = YES;
478478
SDKROOT = iphoneos;
@@ -521,7 +521,7 @@
521521
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
522522
GCC_WARN_UNUSED_FUNCTION = YES;
523523
GCC_WARN_UNUSED_VARIABLE = YES;
524-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
524+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
525525
MTL_ENABLE_DEBUG_INFO = NO;
526526
SDKROOT = iphoneos;
527527
SUPPORTED_PLATFORMS = iphoneos;

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1430"
3+
LastUpgradeVersion = "1510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

example/ios/Runner/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22
import Flutter
33

4-
@UIApplicationMain
4+
@main
55
@objc class AppDelegate: FlutterAppDelegate {
66
override func application(
77
_ application: UIApplication,

example/lib/main.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// import 'package:example/widgets/widgets.dart';
21
import 'package:flutter/material.dart';
32
import 'package:typethis/typethis.dart';
43

@@ -37,7 +36,7 @@ class _MyAppState extends State<MyApp> {
3736
onFreezePressed: () => controller.freeze(),
3837
onUnfreezePressed: () => controller.unfreeze(),
3938
child: TypeThis(
40-
string: 'An example string with typing animation.',
39+
string: 'An example string 💥 with typing 😎 animation. 🚀',
4140
controller: controller,
4241
speed: 100,
4342
style: const TextStyle(fontSize: 16),

lib/src/typethis.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TypeThis extends StatefulWidget {
5555
/// [TextAlign.end] are interpreted.
5656
///
5757
/// This is also used to disambiguate how to render bidirectional text. For
58-
/// example, if the [data] is an English phrase followed by a Hebrew phrase,
58+
/// example, if the [string] is an English phrase followed by a Hebrew phrase,
5959
/// in a [TextDirection.ltr] context the English phrase will be on the left
6060
/// and the Hebrew phrase to its right, while in a [TextDirection.rtl]
6161
/// context, the English phrase will be on the right and the Hebrew phrase on
@@ -160,7 +160,7 @@ class TypeThis extends StatefulWidget {
160160
///
161161
/// `unfreeze` method resumes the typing anmation from where it was frozen last time.
162162
///
163-
/// Remember to [dispose] of the [TypeThisController] when it is no longer
163+
/// Remember to dispose of the [TypeThisController] when it is no longer
164164
/// needed. This will ensure we discard any resources used by the object.
165165
final TypeThisController? controller;
166166

@@ -268,7 +268,7 @@ class _TypeThisState extends State<TypeThis> {
268268
timer.cancel();
269269
} else if (widget.controller?.state == TypeThisControllerState.resumed) {
270270
timer.cancel();
271-
if (currentStep != widget.string.length) {
271+
if (currentStep != widget.string.characters.length) {
272272
_startTimerAndUpdateState();
273273
}
274274
}
@@ -277,7 +277,7 @@ class _TypeThisState extends State<TypeThis> {
277277
void _startTimerAndUpdateState() {
278278
timer = Timer.periodic(Duration(milliseconds: widget.speed), (_) {
279279
currentStep++;
280-
if (currentStep == widget.string.length) {
280+
if (currentStep == widget.string.characters.length) {
281281
timer.cancel();
282282
}
283283
if (mounted) {
@@ -300,10 +300,10 @@ class _TypeThisState extends State<TypeThis> {
300300

301301
for (int i = 0; i < richTextMappers.length; i++) {
302302
final renderedTexts = widgets.map((w) => w.text);
303-
final ongoingLength = renderedTexts.join('').length;
303+
final ongoingLength = renderedTexts.join('').characters.length;
304304

305305
final currentEntry = richTextMappers[i].entries.first;
306-
final currentKeyLength = currentEntry.key.length;
306+
final currentKeyLength = currentEntry.key.characters.length;
307307

308308
if (ongoingLength + currentKeyLength <= subStrEndIndex) {
309309
widgets.add(
@@ -318,7 +318,7 @@ class _TypeThisState extends State<TypeThis> {
318318

319319
widgets.add(
320320
TextSpan(
321-
text: currentEntry.key.substring(0, extraSpace),
321+
text: currentEntry.key.characters.take(extraSpace).toString(),
322322
style: currentEntry.value,
323323
),
324324
);

lib/typethis.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// A flutter package that aims to simplify versatile typing animation
2+
/// with rich text effects and other operations (reset, freeze, unfreeze).
13
library typethis;
24

35
export 'src/blinking_cursor.dart';

test/typethis_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,5 +353,37 @@ void main() {
353353
expect(find.byType(BlinkingCursor), findsOneWidget);
354354
});
355355
});
356+
357+
testWidgets('works with unicode characters (emoji)', (widgetTester) async {
358+
const text = '🚀 string 😃 with 👨‍💻✨ emoji 👀';
359+
await widgetTester.pumpApp(
360+
buildSubject(
361+
string: text,
362+
),
363+
);
364+
await widgetTester.pump(const Duration(milliseconds: 55));
365+
366+
final finder = find.byType(RichText);
367+
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
368+
369+
expect(
370+
richTextWidget.text.toPlainText(),
371+
text.characters.take(1).toString(),
372+
);
373+
374+
await widgetTester.pump(const Duration(milliseconds: 501));
375+
final updatedRichTextWidget = widgetTester.firstWidget<RichText>(finder);
376+
expect(
377+
updatedRichTextWidget.text.toPlainText(),
378+
text.characters.take(11).toString(),
379+
);
380+
381+
await widgetTester.pump(const Duration(seconds: 2));
382+
final wholeRichTextWidget = widgetTester.firstWidget<RichText>(finder);
383+
expect(
384+
wholeRichTextWidget.text.toPlainText(),
385+
text,
386+
);
387+
});
356388
});
357389
}

0 commit comments

Comments
 (0)