diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Animated-Text-Kit.iml b/.idea/Animated-Text-Kit.iml new file mode 100644 index 0000000..a244ef9 --- /dev/null +++ b/.idea/Animated-Text-Kit.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml new file mode 100644 index 0000000..d88bea4 --- /dev/null +++ b/.idea/libraries/Dart_Packages.xml @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml new file mode 100644 index 0000000..a82e8b9 --- /dev/null +++ b/.idea/libraries/Dart_SDK.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml new file mode 100644 index 0000000..b0f6971 --- /dev/null +++ b/.idea/libraries/Flutter_Plugins.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..98863e9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index b18288a..d1e3e93 100644 --- a/README.md +++ b/README.md @@ -281,27 +281,48 @@ return SizedBox( -```dart -return SizedBox( - width: 250.0, - child: DefaultTextStyle( - style: const TextStyle( - fontSize: 30.0, - fontFamily: 'Agne', - ), - child: AnimatedTextKit( - animatedTexts: [ - TypewriterAnimatedText('Discipline is the best tool'), - TypewriterAnimatedText('Design first, then code'), - TypewriterAnimatedText('Do not patch bugs out, rewrite them'), - TypewriterAnimatedText('Do not test bugs out, design them out'), - ], - onTap: () { - print("Tap Event"); - }, - ), - ), -); +``` + return SizedBox( + width: 250.0, + child: DefaultTextStyle( + style: const TextStyle( + fontSize: 30.0, + fontFamily: 'Agne', + ), + child: AnimatedTextKit( + animatedTexts: [ + TypewriterAnimatedText( + 'Discipline is the best tool', + selectionActions: [ + InkWell( + onTap: () { + FocusManager.instance.primaryFocus?.unfocus(); + }, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + color: Colors.black, + padding: const EdgeInsets.all(12), + child: Text( + 'Custom action', + ), + ), + ], + ), + ), + ], + ), + TypewriterAnimatedText('Design first, then code', cursor: '|'), + TypewriterAnimatedText('Do not patch bugs out, rewrite them', + cursor: '<|>'), + TypewriterAnimatedText('Do not test bugs out, design them out', + cursor: '💡'), + ], + onTap: onTap, + ), + ), + ), ``` ## Scale diff --git a/example/lib/main.dart b/example/lib/main.dart index c5c618b..a127508 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -150,7 +150,9 @@ List animatedTextExamples({VoidCallback? onTap}) => ), child: AnimatedTextKit( animatedTexts: [ - RotateAnimatedText('AWESOME'), + RotateAnimatedText( + 'AWESOME', + ), RotateAnimatedText('OPTIMISTIC'), RotateAnimatedText( 'DIFFERENT', @@ -221,7 +223,30 @@ List animatedTextExamples({VoidCallback? onTap}) => ), child: AnimatedTextKit( animatedTexts: [ - TypewriterAnimatedText('Discipline is the best tool'), + TypewriterAnimatedText( + 'Discipline is the best tool', + selectionActions: (selectedText) { + return [ + InkWell( + onTap: () { + FocusManager.instance.primaryFocus?.unfocus(); + }, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + color: Colors.black, + padding: const EdgeInsets.all(12), + child: Text( + 'Custom action', + ), + ), + ], + ), + ), + ]; + }, + ), TypewriterAnimatedText('Design first, then code', cursor: '|'), TypewriterAnimatedText('Do not patch bugs out, rewrite them', cursor: '<|>'), diff --git a/lib/src/typewriter.dart b/lib/src/typewriter.dart index 860c9b5..a974750 100644 --- a/lib/src/typewriter.dart +++ b/lib/src/typewriter.dart @@ -19,6 +19,9 @@ class TypewriterAnimatedText extends AnimatedText { /// By default it is set to Curves.linear. final Curve curve; + ///Action widgets for text selection + final List Function(String selectedText)? selectionActions; + /// Cursor text. Defaults to underscore. final String cursor; @@ -28,6 +31,7 @@ class TypewriterAnimatedText extends AnimatedText { TextStyle? textStyle, this.speed = const Duration(milliseconds: 30), this.curve = Curves.linear, + this.selectionActions, this.cursor = '_', }) : super( text: text, @@ -54,7 +58,26 @@ class TypewriterAnimatedText extends AnimatedText { Widget completeText(BuildContext context) => RichText( text: TextSpan( children: [ - TextSpan(text: text), + if (selectionActions == null) TextSpan(text: text), + if (selectionActions != null) + WidgetSpan( + child: SelectableText( + text, + style: textStyle, + contextMenuBuilder: (context, editableTextState) { + return AdaptiveTextSelectionToolbar( + anchors: editableTextState.contextMenuAnchors, + children: selectionActions?.call(editableTextState + .currentTextEditingValue.text + .substring( + editableTextState + .currentTextEditingValue.selection.start, + editableTextState + .currentTextEditingValue.selection.end)), + ); + }, + ), + ), TextSpan( text: cursor, style: const TextStyle(color: Colors.transparent),