diff --git a/android/build.gradle b/android/build.gradle index 4476887..bb8a303 100644 --- a/android/build.gradle +++ b/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/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index aa901e1..4916623 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/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.10-all.zip diff --git a/lib/jumping_dots.dart b/lib/jumping_dots.dart index 7f8df76..3b60b23 100644 --- a/lib/jumping_dots.dart +++ b/lib/jumping_dots.dart @@ -47,15 +47,16 @@ class JumpingDotsProgressIndicator extends StatefulWidget { } class _JumpingDotsProgressIndicatorState - extends State with TickerProviderStateMixin { + extends State + with SingleTickerProviderStateMixin { int numberOfDots; int milliseconds; double fontSize; double dotSpacing; Color color; - List controllers = new List(); - List> animations = new List>(); - List _widgets = new List(); + AnimationController controller; + List> animations; + List _widgets; _JumpingDotsProgressIndicatorState({ this.numberOfDots, @@ -67,49 +68,64 @@ class _JumpingDotsProgressIndicatorState initState() { super.initState(); - for (int i = 0; i < numberOfDots; i++) { - _addAnimationControllers(); - _buildAnimations(i); - _addListOfDots(i); - } - controllers[0].forward(); - } + final totalDuration = + Duration(milliseconds: widget.milliseconds * widget.numberOfDots); + controller = AnimationController(duration: totalDuration, vsync: this); + controller.addStatusListener((status) { + if (status == AnimationStatus.completed) { + //restarting animation + controller.reset(); + controller.forward(); + } + }); - void _addAnimationControllers() { - controllers.add(AnimationController( - duration: Duration(milliseconds: milliseconds), vsync: this)); - } + // setting up animations for each dot + // how much of the dot animation has to be played before the next dot starts jumping + // 1.0 - each dot jumps after previous has landed + // 0.0 - all dots jumps together + final _jumpDelay = 0.5; + final _animationsInFullJumps = _jumpDelay * widget.numberOfDots + (1.0 - _jumpDelay); + final _jumpDuration = 1.0 / _animationsInFullJumps; + animations = List.generate(widget.numberOfDots, + (index) => _generateDotAnimation(index, _jumpDuration, _jumpDelay)); - void _addListOfDots(int index) { - _widgets.add(Padding( - padding: EdgeInsets.only(right: dotSpacing), - child: _JumpingDot( - animation: animations[index], - fontSize: fontSize, - color: color, - ), - )); + // populate widgets + _widgets = List.generate(widget.numberOfDots, _createDot); + + // start animation + controller.forward(); } - void _buildAnimations(int index) { - animations.add( - Tween(begin: widget.beginTweenValue, end: widget.endTweenValue) - .animate(controllers[index]) - ..addStatusListener((AnimationStatus status) { - if (status == AnimationStatus.completed) - controllers[index].reverse(); - if (index == numberOfDots - 1 && - status == AnimationStatus.dismissed) { - controllers[0].forward(); - } - if (animations[index].value > widget.endTweenValue / 2 && - index < numberOfDots - 1) { - controllers[index + 1].forward(); - } - })); + Animation _generateDotAnimation( + int index, double jumpDuration, double jumpDelay) { + var begin = index * jumpDuration * jumpDelay; + var upAnimation = CurvedAnimation( + parent: controller, + curve: Interval(begin, begin + jumpDuration)); + + Animation downAnimation = CurvedAnimation( + parent: controller, + curve: Interval(begin, begin + jumpDuration)); + + downAnimation = Tween(begin: 1.0, end: 0.0).animate(downAnimation); + + return Tween( + begin: widget.beginTweenValue, + end: widget.endTweenValue * + 2) // to compensate using AnimationMin (max value is 0.5) + .animate(AnimationMin(upAnimation, downAnimation)); } + Widget _createDot(int index) => Padding( + padding: EdgeInsets.only(right: dotSpacing), + child: _JumpingDot( + animation: animations[index], + fontSize: fontSize, + color: color, + ), + ); + Widget build(BuildContext context) { return SizedBox( height: 30.0, @@ -121,7 +137,7 @@ class _JumpingDotsProgressIndicatorState } dispose() { - for (int i = 0; i < numberOfDots; i++) controllers[i].dispose(); + controller.dispose(); super.dispose(); } -} \ No newline at end of file +} diff --git a/pubspec.lock b/pubspec.lock index 1890398..7eebb6b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,69 +1,34 @@ # Generated by pub # See https://www.dartlang.org/tools/pub/glossary#lockfile packages: - analyzer: - dependency: transitive - description: - name: analyzer - url: "https://pub.dartlang.org" - source: hosted - version: "0.31.2-alpha.2" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.3" 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" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.3" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.4" + version: "1.14.11" cupertino_icons: dependency: "direct main" description: @@ -81,290 +46,94 @@ packages: description: flutter source: sdk version: "0.0.0" - front_end: - dependency: transitive - description: - name: front_end - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.0-alpha.12" - glob: - dependency: transitive - description: - name: glob - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.5" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.13.3" - http: - dependency: transitive - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+16" - http_multi_server: - dependency: transitive - description: - name: http_multi_server - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.4" - http_parser: - dependency: transitive - description: - name: http_parser - url: "https://pub.dartlang.org" - source: hosted - version: "3.1.2" - io: - dependency: transitive - description: - name: io - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.2+1" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.1" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.0-alpha.12" - logging: - dependency: transitive - description: - name: logging - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+1" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.2+1" + version: "0.12.3+1" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" - mime: - dependency: transitive - description: - name: mime - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.6" - multi_server_socket: - dependency: transitive - description: - name: multi_server_socket - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1" - node_preamble: - dependency: transitive - description: - name: node_preamble - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.1" - package_config: - dependency: transitive - description: - name: package_config - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.3" - package_resolver: - dependency: transitive - description: - name: package_resolver - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.2" + version: "1.1.6" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.5.1" - plugin: - dependency: transitive - description: - name: plugin - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0+2" - pool: - dependency: transitive - description: - name: pool - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.4" - pub_semver: - dependency: transitive - description: - name: pub_semver - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.1" + version: "1.6.2" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "0.29.0+1" - shelf: - dependency: transitive - description: - name: shelf - url: "https://pub.dartlang.org" - source: hosted - version: "0.7.3" - shelf_packages_handler: - dependency: transitive - description: - name: shelf_packages_handler - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.3" - shelf_static: - dependency: transitive - description: - name: shelf_static - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.7" - shelf_web_socket: - dependency: transitive - description: - name: shelf_web_socket - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.2" + version: "2.0.1" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" - source_map_stack_trace: - dependency: transitive - description: - name: source_map_stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.4" - source_maps: - dependency: transitive - description: - name: source_maps - url: "https://pub.dartlang.org" - source: hosted - version: "0.10.5" 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.6" + 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" - test: + version: "1.0.1" + test_api: dependency: transitive description: - name: test + name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.12.37" + version: "0.2.1" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" - utf: - dependency: transitive - description: - name: utf - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.0+4" + version: "1.1.6" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" - watcher: - dependency: transitive - description: - name: watcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.7+7" - web_socket_channel: - dependency: transitive - description: - name: web_socket_channel - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.7" - yaml: - dependency: transitive - description: - name: yaml - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.13" + version: "2.0.8" sdks: - dart: ">=2.0.0-dev.52.0 <=2.0.0-dev.58.0.flutter-f981f09760" + dart: ">=2.0.0 <3.0.0"