diff --git a/.gitignore b/.gitignore index be02915..efbfdbf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,33 @@ .DS_Store -.dart_tool/ +.atom/ +.idea/ +.vscode/ .packages .pub/ +.dart_tool/ +pubspec.lock -build/ -ios/.generated/ -ios/Flutter/Generated.xcconfig -ios/Runner/GeneratedPluginRegistrant.* +Podfile +Podfile.lock +Pods/ +.symlinks/ +**/Flutter/App.framework/ +**/Flutter/Flutter.framework/ +**/Flutter/Generated.xcconfig +**/Flutter/flutter_assets/ +ServiceDefinitions.json +xcuserdata/ -# IntelliJ -.idea -*.iml \ No newline at end of file +local.properties +.gradle/ +gradlew +gradlew.bat +gradle-wrapper.jar +*.iml + +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m +GeneratedPluginRegistrant.java +build/ +.flutter-plugins \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a6eae50..a9b1168 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: - FLUTTER_VERSION=dev matrix: allow_failures: - - env: FLUTTER_VERSION=beta + - env: FLUTTER_VERSION=dev before_script: - cd ../ - git clone https://github.com/flutter/flutter.git -b $FLUTTER_VERSION diff --git a/CHANGELOG.md b/CHANGELOG.md index f8596ec..582bf2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.2.0 +**Feature Enhancement** +* Added attribute to check whether the animation should repeat or not. +* Updated Readme. + ## 1.1.1 * Fixed flutter formatting issues. diff --git a/README.md b/README.md index 034daaf..3efb54b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Add this to your package's `pubspec.yaml` file: ```yaml dependencies: - animated_text_kit: ^1.1.1 + animated_text_kit: ^1.2.0 ``` ### 2. Install it @@ -72,10 +72,11 @@ import 'package:animated_text_kit/animated_text_kit.dart'; # Usage -You can override the `duration` of each animation by setting duration in each AnimatedTextKit class. For example: +You can override the `duration` of each animation by setting its duration in each AnimatedTextKit class, also you can set if the animation should not repeat by changing the value of `isRepeatingAnimation` to false. For example: ```dart FadeAnimatedTextKit( duration: Duration(milliseconds: 5000), + isRepeatingAnimation: false, text: ["do IT!", "do it RIGHT!!", "do it RIGHT NOW!!!"], textStyle: TextStyle(fontSize: 32.0, fontWeight: FontWeight.bold), ); @@ -233,7 +234,7 @@ SizedBox( ), ); ``` -**Note:** `colors` list should contains at least two values, also `ColorizeAnimationTextKit` can be used for flutter `>=0.5.7` which is available in `dev` channel. +**Note:** `colors` list should contains at least two values. # Bugs or Requests diff --git a/example/android/build.gradle b/example/android/build.gradle index b2483d3..a7cc6e1 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.2.1' } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 651b997..9a2d3fe 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/example/android/gradlew b/example/android/gradlew old mode 100644 new mode 100755 diff --git a/example/lib/main.dart b/example/lib/main.dart index 4df624c..1d6bcc1 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -68,6 +68,7 @@ class _MyHomePageState extends State { onTap: () { print("Tap Event"); }, + isRepeatingAnimation: false, text: ["AWESOME", "OPTIMISTIC", "DIFFERENT"], textStyle: TextStyle(fontSize: 40.0, fontFamily: "Horizon"), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index dc1b5fc..49b8fe5 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,70 +7,70 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.31.2-alpha.2" + version: "0.33.0" animated_text_kit: dependency: "direct dev" description: path: ".." relative: true source: path - version: "1.1.0" + version: "1.1.1" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.4.3" + version: "1.5.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.7" + version: "2.0.8" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "1.1.2" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.6" + version: "1.14.11" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.2" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.6" csslib: dependency: transitive description: name: csslib url: "https://pub.dartlang.org" source: hosted - version: "0.14.4" + version: "0.14.6" cupertino_icons: dependency: "direct main" description: @@ -94,28 +94,28 @@ packages: name: front_end url: "https://pub.dartlang.org" source: hosted - version: "0.1.0-alpha.12" + version: "0.1.6" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "1.1.7" html: dependency: transitive description: name: html url: "https://pub.dartlang.org" source: hosted - version: "0.13.3+1" + version: "0.13.3+3" http: dependency: transitive description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.11.3+16" + version: "0.12.0" http_multi_server: dependency: transitive description: @@ -129,154 +129,154 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.2" + version: "3.1.3" io: dependency: transitive description: name: io url: "https://pub.dartlang.org" source: hosted - version: "0.3.2+1" + version: "0.3.3" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.1" + version: "0.6.1+1" json_rpc_2: dependency: transitive description: name: json_rpc_2 url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.9" kernel: dependency: transitive description: name: kernel url: "https://pub.dartlang.org" source: hosted - version: "0.3.0-alpha.12" + version: "0.3.6" logging: dependency: transitive description: name: logging url: "https://pub.dartlang.org" source: hosted - version: "0.11.3+1" + version: "0.11.3+2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.2" + version: "0.12.3+1" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "1.1.6" mime: dependency: transitive description: name: mime url: "https://pub.dartlang.org" source: hosted - version: "0.9.6+1" + version: "0.9.6+2" multi_server_socket: dependency: transitive description: name: multi_server_socket url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" node_preamble: dependency: transitive description: name: node_preamble url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "1.4.4" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.5" package_resolver: dependency: transitive description: name: package_resolver url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.6" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.1" + version: "1.6.2" plugin: dependency: transitive description: name: plugin url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+2" + version: "0.2.0+3" pool: dependency: transitive description: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.3.5" + version: "1.3.6" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.4.2" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "0.29.0+1" + version: "2.0.0+1" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "0.7.3+1" + version: "0.7.3+3" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" shelf_static: dependency: transitive description: name: shelf_static url: "https://pub.dartlang.org" source: hosted - version: "0.2.7+1" + version: "0.2.8" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "0.2.2+2" + version: "0.2.2+4" sky_engine: dependency: transitive description: flutter @@ -288,105 +288,105 @@ packages: name: source_map_stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.1.4" + version: "1.1.5" source_maps: dependency: transitive description: name: source_maps url: "https://pub.dartlang.org" source: hosted - version: "0.10.5" + version: "0.10.8" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.4.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.2" + version: "1.9.3" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.6.7+1" + version: "1.6.8" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.4" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.0.1" test: dependency: transitive description: name: test url: "https://pub.dartlang.org" source: hosted - version: "0.12.41" + version: "1.3.4" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "1.1.6" utf: dependency: transitive description: name: utf url: "https://pub.dartlang.org" source: hosted - version: "0.9.0+4" + version: "0.9.0+5" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "2.0.8" vm_service_client: dependency: transitive description: name: vm_service_client url: "https://pub.dartlang.org" source: hosted - version: "0.2.4+3" + version: "0.2.6" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+8" + version: "0.9.7+10" web_socket_channel: dependency: transitive description: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "1.0.8" + version: "1.0.9" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.14" + version: "2.1.15" sdks: - dart: ">=2.0.0-dev.62.0 <=2.0.0-dev.63.0.flutter-4c9689c1d2" + dart: ">=2.0.0 <3.0.0" flutter: ">=0.3.0 <2.0.0" diff --git a/lib/src/colorize.dart b/lib/src/colorize.dart index 18481a6..44ddbeb 100644 --- a/lib/src/colorize.dart +++ b/lib/src/colorize.dart @@ -6,6 +6,7 @@ class ColorizeAnimatedTextKit extends StatefulWidget { final TextStyle textStyle; final Duration duration; final VoidCallback onTap; + final bool isRepeatingAnimation; const ColorizeAnimatedTextKit( {Key key, @@ -13,7 +14,8 @@ class ColorizeAnimatedTextKit extends StatefulWidget { this.textStyle, @required this.colors, this.duration, - this.onTap}) + this.onTap, + this.isRepeatingAnimation = true}) : super(key: key); @override @@ -56,7 +58,13 @@ class _RotatingTextState extends State _controller = new AnimationController( duration: _duration, vsync: this, - )..repeat(); + ); + + if (widget.isRepeatingAnimation) { + _controller..repeat(); + } else { + _controller.forward(); + } double percentTimeCount = 0.0; @@ -103,26 +111,70 @@ class _RotatingTextState extends State @override Widget build(BuildContext context) { for (int i = 0; i < widget.text.length; i++) { - _textWidgetList.add(AnimatedBuilder( - animation: _controller, - builder: (BuildContext context, Widget child) { - Shader linearGradient = LinearGradient(colors: widget.colors) - .createShader( - Rect.fromLTWH(0.0, 0.0, _colorShifter[i].value, 0.0)); - return Opacity( - opacity: !(_fadeIn[i].value == 1.0) - ? _fadeIn[i].value - : _fadeOut[i].value, - child: Text( - widget.text[i], - style: widget.textStyle != null - ? widget.textStyle.merge( - TextStyle(foreground: Paint()..shader = linearGradient)) - : widget.textStyle, - ), - ); - }, - )); + if (i != widget.text.length - 1) { + _textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + Shader linearGradient = LinearGradient(colors: widget.colors) + .createShader( + Rect.fromLTWH(0.0, 0.0, _colorShifter[i].value, 0.0)); + return Opacity( + opacity: !(_fadeIn[i].value == 1.0) + ? _fadeIn[i].value + : _fadeOut[i].value, + child: Text( + widget.text[i], + style: widget.textStyle != null + ? widget.textStyle.merge( + TextStyle(foreground: Paint()..shader = linearGradient)) + : widget.textStyle, + ), + ); + }, + )); + } else { + if (widget.isRepeatingAnimation) { + _textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + Shader linearGradient = LinearGradient(colors: widget.colors) + .createShader( + Rect.fromLTWH(0.0, 0.0, _colorShifter[i].value, 0.0)); + return Opacity( + opacity: !(_fadeIn[i].value == 1.0) + ? _fadeIn[i].value + : _fadeOut[i].value, + child: Text( + widget.text[i], + style: widget.textStyle != null + ? widget.textStyle.merge(TextStyle( + foreground: Paint()..shader = linearGradient)) + : widget.textStyle, + ), + ); + }, + )); + } else { + _textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + Shader linearGradient = LinearGradient(colors: widget.colors) + .createShader( + Rect.fromLTWH(0.0, 0.0, _colorShifter[i].value, 0.0)); + return Opacity( + opacity: _fadeIn[i].value, + child: Text( + widget.text[i], + style: widget.textStyle != null + ? widget.textStyle.merge(TextStyle( + foreground: Paint()..shader = linearGradient)) + : widget.textStyle, + ), + ); + }, + )); + } + } } return SizedBox( diff --git a/lib/src/fade.dart b/lib/src/fade.dart index 2128bde..b43e584 100644 --- a/lib/src/fade.dart +++ b/lib/src/fade.dart @@ -5,9 +5,15 @@ class FadeAnimatedTextKit extends StatefulWidget { final TextStyle textStyle; final Duration duration; final VoidCallback onTap; + final bool isRepeatingAnimation; const FadeAnimatedTextKit( - {Key key, @required this.text, this.textStyle, this.duration, this.onTap}) + {Key key, + @required this.text, + this.textStyle, + this.duration, + this.onTap, + this.isRepeatingAnimation = true}) : super(key: key); @override @@ -38,7 +44,13 @@ class _RotatingTextState extends State _controller = new AnimationController( duration: _duration, vsync: this, - )..repeat(); + ); + + if (widget.isRepeatingAnimation) { + _controller..repeat(); + } else { + _controller.forward(); + } int lengthList = widget.text.length; @@ -67,20 +79,52 @@ class _RotatingTextState extends State @override Widget build(BuildContext context) { for (int i = 0; i < widget.text.length; i++) { - textWidgetList.add(AnimatedBuilder( - animation: _controller, - builder: (BuildContext context, Widget child) { - return Opacity( - opacity: !(_fadeIn[i].value == 1.0) - ? _fadeIn[i].value - : _fadeOut[i].value, - child: Text( - widget.text[i], - style: widget.textStyle, - ), - ); - }, - )); + if (i != widget.text.length - 1) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: !(_fadeIn[i].value == 1.0) + ? _fadeIn[i].value + : _fadeOut[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), + ); + }, + )); + } else { + if (widget.isRepeatingAnimation) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: !(_fadeIn[i].value == 1.0) + ? _fadeIn[i].value + : _fadeOut[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), + ); + }, + )); + } else { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: _fadeIn[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), + ); + }, + )); + } + } } return GestureDetector( diff --git a/lib/src/rotate.dart b/lib/src/rotate.dart index d767fd4..9aaf3ef 100644 --- a/lib/src/rotate.dart +++ b/lib/src/rotate.dart @@ -6,6 +6,7 @@ class RotateAnimatedTextKit extends StatefulWidget { final Duration duration; final double transitionHeight; final VoidCallback onTap; + final bool isRepeatingAnimation; const RotateAnimatedTextKit( {Key key, @@ -13,7 +14,8 @@ class RotateAnimatedTextKit extends StatefulWidget { this.textStyle, this.transitionHeight, this.duration, - this.onTap}) + this.onTap, + this.isRepeatingAnimation = true}) : super(key: key); @override @@ -48,7 +50,13 @@ class _RotatingTextState extends State _controller = new AnimationController( duration: _duration, vsync: this, - )..repeat(); + ); + + if (widget.isRepeatingAnimation) { + _controller..repeat(); + } else { + _controller.forward(); + } int lengthList = widget.text.length; @@ -87,6 +95,7 @@ class _RotatingTextState extends State (i * percentTime) - slideTime + fadeTime, curve: Curves.easeOut)))); } + _slideOut.add(AlignmentTween( begin: Alignment(-1.0, 0.0), end: new Alignment(-1.0, 1.0), @@ -112,24 +121,63 @@ class _RotatingTextState extends State @override Widget build(BuildContext context) { for (int i = 0; i < widget.text.length; i++) { - textWidgetList.add(AnimatedBuilder( - animation: _controller, - builder: (BuildContext context, Widget child) { - return AlignTransition( - alignment: - !(_slideIn[i].value.y == 0.0) ? _slideIn[i] : _slideOut[i], - child: Opacity( - opacity: !(_fadeIn[i].value == 1.0) - ? _fadeIn[i].value - : _fadeOut[i].value, - child: Text( - widget.text[i], - style: widget.textStyle, + if (i != widget.text.length - 1) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return AlignTransition( + alignment: + !(_slideIn[i].value.y == 0.0) ? _slideIn[i] : _slideOut[i], + child: Opacity( + opacity: !(_fadeIn[i].value == 1.0) + ? _fadeIn[i].value + : _fadeOut[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), ), - ), - ); - }, - )); + ); + }, + )); + } else { + if (widget.isRepeatingAnimation) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return AlignTransition( + alignment: + !(_slideIn[i].value.y == 0.0) ? _slideIn[i] : _slideOut[i], + child: Opacity( + opacity: !(_fadeIn[i].value == 1.0) + ? _fadeIn[i].value + : _fadeOut[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), + ), + ); + }, + )); + } else { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return AlignTransition( + alignment: _slideIn[i], + child: Opacity( + opacity: _fadeIn[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), + ), + ); + }, + )); + } + } } return GestureDetector( diff --git a/lib/src/scale.dart b/lib/src/scale.dart index f37ac87..5f7ad0f 100644 --- a/lib/src/scale.dart +++ b/lib/src/scale.dart @@ -6,6 +6,7 @@ class ScaleAnimatedTextKit extends StatefulWidget { final Duration duration; final double scalingFactor; final VoidCallback onTap; + final bool isRepeatingAnimation; const ScaleAnimatedTextKit( {Key key, @@ -13,7 +14,8 @@ class ScaleAnimatedTextKit extends StatefulWidget { this.textStyle, this.scalingFactor = 0.5, this.duration, - this.onTap}) + this.onTap, + this.isRepeatingAnimation = true}) : super(key: key); @override @@ -46,7 +48,13 @@ class _RotatingTextState extends State _controller = new AnimationController( duration: _duration, vsync: this, - )..repeat(); + ); + + if (widget.isRepeatingAnimation) { + _controller..repeat(); + } else { + _controller.forward(); + } int lengthList = widget.text.length; @@ -92,23 +100,61 @@ class _RotatingTextState extends State @override Widget build(BuildContext context) { for (int i = 0; i < widget.text.length; i++) { - textWidgetList.add(AnimatedBuilder( - animation: _controller, - builder: (BuildContext context, Widget child) { - return ScaleTransition( - scale: !(_scaleIn[i].value == 1.0) ? _scaleIn[i] : _scaleOut[i], - child: Opacity( - opacity: !(_fadeIn[i].value == 1.0) - ? _fadeIn[i].value - : _fadeOut[i].value, - child: Text( - widget.text[i], - style: widget.textStyle, + if (i != widget.text.length - 1) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return ScaleTransition( + scale: !(_scaleIn[i].value == 1.0) ? _scaleIn[i] : _scaleOut[i], + child: Opacity( + opacity: !(_fadeIn[i].value == 1.0) + ? _fadeIn[i].value + : _fadeOut[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), ), - ), - ); - }, - )); + ); + }, + )); + } else { + if (widget.isRepeatingAnimation) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return ScaleTransition( + scale: !(_scaleIn[i].value == 1.0) ? _scaleIn[i] : _scaleOut[i], + child: Opacity( + opacity: !(_fadeIn[i].value == 1.0) + ? _fadeIn[i].value + : _fadeOut[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), + ), + ); + }, + )); + } else { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return ScaleTransition( + scale: _scaleIn[i], + child: Opacity( + opacity: _fadeIn[i].value, + child: Text( + widget.text[i], + style: widget.textStyle, + ), + ), + ); + }, + )); + } + } } return GestureDetector( diff --git a/lib/src/typer.dart b/lib/src/typer.dart index 992aebf..c1a796b 100644 --- a/lib/src/typer.dart +++ b/lib/src/typer.dart @@ -5,9 +5,15 @@ class TyperAnimatedTextKit extends StatefulWidget { final TextStyle textStyle; final Duration duration; final VoidCallback onTap; + final bool isRepeatingAnimation; const TyperAnimatedTextKit( - {Key key, @required this.text, this.textStyle, this.duration, this.onTap}) + {Key key, + @required this.text, + this.textStyle, + this.duration, + this.onTap, + this.isRepeatingAnimation = true}) : super(key: key); @override @@ -44,7 +50,13 @@ class _TyperState extends State _controller = new AnimationController( duration: _duration, vsync: this, - )..repeat(); + ); + + if (widget.isRepeatingAnimation) { + _controller..repeat(); + } else { + _controller.forward(); + } double percentTimeCount = 0.0; for (int i = 0; i < widget.text.length; i++) { @@ -76,18 +88,48 @@ class _TyperState extends State @override Widget build(BuildContext context) { for (int i = 0; i < widget.text.length; i++) { - textWidgetList.add(AnimatedBuilder( - animation: _controller, - builder: (BuildContext context, Widget child) { - return Opacity( - opacity: _fadeOut[i].value, - child: Text( - widget.text[i].substring(0, _typingText[i].value), - style: widget.textStyle, - ), - ); - }, - )); + if (i != widget.text.length - 1) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: _fadeOut[i].value, + child: Text( + widget.text[i].substring(0, _typingText[i].value), + style: widget.textStyle, + ), + ); + }, + )); + } else { + if (widget.isRepeatingAnimation) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: _fadeOut[i].value, + child: Text( + widget.text[i].substring(0, _typingText[i].value), + style: widget.textStyle, + ), + ); + }, + )); + } else { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: 1, + child: Text( + widget.text[i].substring(0, _typingText[i].value), + style: widget.textStyle, + ), + ); + }, + )); + } + } } return GestureDetector( diff --git a/lib/src/typewriter.dart b/lib/src/typewriter.dart index 237bb3e..2592b46 100644 --- a/lib/src/typewriter.dart +++ b/lib/src/typewriter.dart @@ -5,9 +5,15 @@ class TypewriterAnimatedTextKit extends StatefulWidget { final TextStyle textStyle; final Duration duration; final VoidCallback onTap; + final bool isRepeatingAnimation; TypewriterAnimatedTextKit( - {Key key, @required this.text, this.textStyle, this.duration, this.onTap}) + {Key key, + @required this.text, + this.textStyle, + this.duration, + this.onTap, + this.isRepeatingAnimation = true}) : super(key: key); @override @@ -44,7 +50,13 @@ class _TypewriterState extends State _controller = new AnimationController( duration: _duration, vsync: this, - )..repeat(); + ); + + if (widget.isRepeatingAnimation) { + _controller..repeat(); + } else { + _controller.forward(); + } int totalCharacters = 0; @@ -82,40 +94,119 @@ class _TypewriterState extends State @override Widget build(BuildContext context) { for (int i = 0; i < widget.text.length; i++) { - textWidgetList.add(AnimatedBuilder( - animation: _controller, - builder: (BuildContext context, Widget child) { - return Opacity( - opacity: _fadeOut[i].value, - child: Builder( - builder: (BuildContext context) { - String visibleString = widget.text[i]; - if (_typewriterText[i].value == 0) { - visibleString = ""; - } else if (_typewriterText[i].value > widget.text[i].length) { - if ((_typewriterText[i].value - widget.text[i].length) % 2 == - 0) { - visibleString = - widget.text[i].substring(0, widget.text[i].length) + - "_"; + if (i != widget.text.length - 1) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: _fadeOut[i].value, + child: Builder( + builder: (BuildContext context) { + String visibleString = widget.text[i]; + if (_typewriterText[i].value == 0) { + visibleString = ""; + } else if (_typewriterText[i].value > widget.text[i].length) { + if ((_typewriterText[i].value - widget.text[i].length) % + 2 == + 0) { + visibleString = + widget.text[i].substring(0, widget.text[i].length) + + "_"; + } else { + visibleString = + widget.text[i].substring(0, widget.text[i].length); + } } else { visibleString = - widget.text[i].substring(0, widget.text[i].length); + widget.text[i].substring(0, _typewriterText[i].value) + + "_"; } - } else { - visibleString = - widget.text[i].substring(0, _typewriterText[i].value) + + return Text( + visibleString, + style: widget.textStyle, + ); + }, + ), + ); + }, + )); + } else { + if (widget.isRepeatingAnimation) { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: _fadeOut[i].value, + child: Builder( + builder: (BuildContext context) { + String visibleString = widget.text[i]; + if (_typewriterText[i].value == 0) { + visibleString = ""; + } else if (_typewriterText[i].value > + widget.text[i].length) { + if ((_typewriterText[i].value - widget.text[i].length) % + 2 == + 0) { + visibleString = + widget.text[i].substring(0, widget.text[i].length) + + "_"; + } else { + visibleString = + widget.text[i].substring(0, widget.text[i].length); + } + } else { + visibleString = widget.text[i] + .substring(0, _typewriterText[i].value) + "_"; - } - return Text( - visibleString, - style: widget.textStyle, - ); - }, - ), - ); - }, - )); + } + return Text( + visibleString, + style: widget.textStyle, + ); + }, + ), + ); + }, + )); + } else { + textWidgetList.add(AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget child) { + return Opacity( + opacity: 1, + child: Builder( + builder: (BuildContext context) { + String visibleString = widget.text[i]; + if (_typewriterText[i].value == 0) { + visibleString = ""; + } else if (_typewriterText[i].value > + widget.text[i].length) { + if ((_typewriterText[i].value - widget.text[i].length) % + 2 == + 0) { + visibleString = + widget.text[i].substring(0, widget.text[i].length) + + "_"; + } else { + visibleString = + widget.text[i].substring(0, widget.text[i].length); + } + } else { + visibleString = widget.text[i] + .substring(0, _typewriterText[i].value) + + "_"; + } + return Text( + visibleString, + style: widget.textStyle, + ); + }, + ), + ); + }, + )); + } + } } return GestureDetector( diff --git a/pubspec.lock b/pubspec.lock index fd3c561..736c918 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,63 +7,63 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.31.2-alpha.2" + version: "0.33.0" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.4.3" + version: "1.5.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.7" + version: "2.0.8" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "1.1.2" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.6" + version: "1.14.11" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.2" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.6" csslib: dependency: transitive description: name: csslib url: "https://pub.dartlang.org" source: hosted - version: "0.14.4" + version: "0.14.6" flutter: dependency: "direct main" description: flutter @@ -80,28 +80,28 @@ packages: name: front_end url: "https://pub.dartlang.org" source: hosted - version: "0.1.0-alpha.12" + version: "0.1.6" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "1.1.7" html: dependency: transitive description: name: html url: "https://pub.dartlang.org" source: hosted - version: "0.13.3+1" + version: "0.13.3+3" http: dependency: transitive description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.11.3+16" + version: "0.12.0" http_multi_server: dependency: transitive description: @@ -115,154 +115,154 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.2" + version: "3.1.3" io: dependency: transitive description: name: io url: "https://pub.dartlang.org" source: hosted - version: "0.3.2+1" + version: "0.3.3" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.1" + version: "0.6.1+1" json_rpc_2: dependency: transitive description: name: json_rpc_2 url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.9" kernel: dependency: transitive description: name: kernel url: "https://pub.dartlang.org" source: hosted - version: "0.3.0-alpha.12" + version: "0.3.6" logging: dependency: transitive description: name: logging url: "https://pub.dartlang.org" source: hosted - version: "0.11.3+1" + version: "0.11.3+2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.2" + version: "0.12.3+1" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "1.1.6" mime: dependency: transitive description: name: mime url: "https://pub.dartlang.org" source: hosted - version: "0.9.6+1" + version: "0.9.6+2" multi_server_socket: dependency: transitive description: name: multi_server_socket url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" node_preamble: dependency: transitive description: name: node_preamble url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "1.4.4" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.5" package_resolver: dependency: transitive description: name: package_resolver url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.6" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.1" + version: "1.6.2" plugin: dependency: transitive description: name: plugin url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+2" + version: "0.2.0+3" pool: dependency: transitive description: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.3.5" + version: "1.3.6" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.4.2" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "0.29.0+1" + version: "2.0.0+1" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "0.7.3+1" + version: "0.7.3+3" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" shelf_static: dependency: transitive description: name: shelf_static url: "https://pub.dartlang.org" source: hosted - version: "0.2.7+1" + version: "0.2.8" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "0.2.2+2" + version: "0.2.2+4" sky_engine: dependency: transitive description: flutter @@ -274,105 +274,105 @@ packages: name: source_map_stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.1.4" + version: "1.1.5" source_maps: dependency: transitive description: name: source_maps url: "https://pub.dartlang.org" source: hosted - version: "0.10.5" + version: "0.10.8" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.4.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.2" + version: "1.9.3" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.6.7+1" + version: "1.6.8" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.4" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.0.1" test: dependency: transitive description: name: test url: "https://pub.dartlang.org" source: hosted - version: "0.12.41" + version: "1.3.4" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "1.1.6" utf: dependency: transitive description: name: utf url: "https://pub.dartlang.org" source: hosted - version: "0.9.0+4" + version: "0.9.0+5" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "2.0.8" vm_service_client: dependency: transitive description: name: vm_service_client url: "https://pub.dartlang.org" source: hosted - version: "0.2.4+3" + version: "0.2.6" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+8" + version: "0.9.7+10" web_socket_channel: dependency: transitive description: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "1.0.8" + version: "1.0.9" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.14" + version: "2.1.15" sdks: - dart: ">=2.0.0-dev.62.0 <=2.0.0-dev.63.0.flutter-4c9689c1d2" + dart: ">=2.0.0 <3.0.0" flutter: ">=0.3.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index f26b7a0..5142c88 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: animated_text_kit description: A flutter package project which contains a collection of cool and beautiful text animations. -version: 1.1.1 +version: 1.2.0 author: Ayush Agarwal homepage: https://github.com/aagarwal1012/Animated-Text-Kit/