From 2c6fff20cfa2e80ed75f74e4549891e6bac87c56 Mon Sep 17 00:00:00 2001 From: Jeremiah Ogbomo Date: Fri, 28 Dec 2018 09:34:14 +0100 Subject: [PATCH] release: 3.1.0 (#47) * fix: state disposed before ticker Fixes #46 * chore: handle analysis issues * feat: duration parameter Closes #43 * chore: code clean up * chore: update changelog --- CHANGELOG.md | 16 +- README.md | 2 +- analysis_options.yaml | 2 - example/pubspec.lock | 257 +------------------------------- lib/src/chasing_dots.dart | 15 +- lib/src/circle.dart | 13 +- lib/src/cube_grid.dart | 30 ++-- lib/src/double_bounce.dart | 16 +- lib/src/dual_ring.dart | 25 ++-- lib/src/fading_circle.dart | 13 +- lib/src/fading_cube.dart | 13 +- lib/src/fading_four.dart | 15 +- lib/src/fading_grid.dart | 20 +-- lib/src/folding_cube.dart | 21 +-- lib/src/hour_glass.dart | 24 +-- lib/src/pouring_hour_glass.dart | 32 ++-- lib/src/pulse.dart | 13 +- lib/src/pumping_heart.dart | 20 +-- lib/src/ring.dart | 55 +++---- lib/src/ripple.dart | 19 +-- lib/src/rotating_circle.dart | 20 +-- lib/src/rotating_plain.dart | 17 ++- lib/src/spinning_circle.dart | 20 +-- lib/src/three_bounce.dart | 20 ++- lib/src/utils.dart | 8 +- lib/src/wandering_cubes.dart | 39 ++--- lib/src/wave.dart | 28 ++-- pubspec.lock | 255 +------------------------------ pubspec.yaml | 2 +- 29 files changed, 284 insertions(+), 746 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b178573..a722af0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,18 @@ -# 3.0.0 +# ChangeLog for Flutter Spinkit + +A collection of loading indicators animated with flutter. Heavily inspired by @tobiasahlin's SpinKit. + +## 3.1.0 + +### Feature + +- duration parameter [70b113b](https://github.com/jogboms/flutter_spinkit/commit/70b113b384200e344336d521704a1c96d2864909) + +### Fixes + +- state disposed before ticker [0c9b6e3](https://github.com/jogboms/flutter_spinkit/commit/0c9b6e388c2f714659b945ece7feb3b7480ba0de) + +## 3.0.0 ### Before diff --git a/README.md b/README.md index 93eee1c..4732e71 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A collection of loading indicators animated with flutter. Heavily inspired by [@ ```yaml dependencies: - flutter_spinkit: "^3.0.0" + flutter_spinkit: "^3.1.0" ``` ### ⚡️ Import diff --git a/analysis_options.yaml b/analysis_options.yaml index 2569a14..1221796 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -22,8 +22,6 @@ # in sync with this file. analyzer: - language: - enableSuperMixins: true strong-mode: implicit-dynamic: false errors: diff --git a/example/pubspec.lock b/example/pubspec.lock index 5e1856f..b5fea75 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,20 +1,6 @@ # 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.32.4" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.0" async: dependency: transitive description: @@ -43,27 +29,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.2" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.6" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.5" flutter: dependency: "direct main" description: flutter @@ -75,89 +40,12 @@ packages: path: ".." relative: true source: path - version: "3.0.0" + version: "3.1.0" flutter_test: dependency: "direct dev" 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.4" - glob: - dependency: transitive - description: - name: glob - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.7" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.13.3+3" - http: - dependency: transitive - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+17" - http_multi_server: - dependency: transitive - description: - name: http_multi_server - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" - http_parser: - dependency: transitive - description: - name: http_parser - url: "https://pub.dartlang.org" - source: hosted - version: "3.1.3" - io: - dependency: transitive - description: - name: io - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.3" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - 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.9" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.4" - logging: - dependency: transitive - description: - name: logging - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+2" matcher: dependency: transitive description: @@ -172,41 +60,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" - mime: - dependency: transitive - description: - name: mime - url: "https://pub.dartlang.org" - source: hosted - 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.2" - node_preamble: - dependency: transitive - description: - name: node_preamble - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.4" - package_config: - dependency: transitive - description: - name: package_config - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - package_resolver: - dependency: transitive - description: - name: package_resolver - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.4" path: dependency: transitive description: @@ -214,81 +67,18 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.2" - plugin: - dependency: transitive - description: - name: plugin - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0+3" - pool: - dependency: transitive - description: - name: pool - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.6" - pub_semver: - dependency: transitive - description: - name: pub_semver - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.2" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.0+1" - shelf: - dependency: transitive - description: - name: shelf - url: "https://pub.dartlang.org" - source: hosted - 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.4" - shelf_static: - dependency: transitive - description: - name: shelf_static - url: "https://pub.dartlang.org" - source: hosted - 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+4" + 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.5" - source_maps: - dependency: transitive - description: - name: source_maps - url: "https://pub.dartlang.org" - source: hosted - version: "0.10.7" source_span: dependency: transitive description: @@ -324,13 +114,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.1" - test: + test_api: dependency: transitive description: - name: test + name: test_api url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "0.2.1" typed_data: dependency: transitive description: @@ -338,13 +128,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" - utf: - dependency: transitive - description: - name: utf - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.0+5" vector_math: dependency: transitive description: @@ -352,34 +135,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" - vm_service_client: - dependency: transitive - description: - name: vm_service_client - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.6" - watcher: - dependency: transitive - description: - name: watcher - url: "https://pub.dartlang.org" - source: hosted - 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.9" - yaml: - dependency: transitive - description: - name: yaml - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.15" sdks: - dart: ">=2.0.0-dev.68.0 <3.0.0" + dart: ">=2.0.0 <3.0.0" flutter: ">=0.1.4 <2.0.0" diff --git a/lib/src/chasing_dots.dart b/lib/src/chasing_dots.dart index 3d6d053..dbd4643 100644 --- a/lib/src/chasing_dots.dart +++ b/lib/src/chasing_dots.dart @@ -1,15 +1,12 @@ import 'package:flutter/material.dart'; class SpinKitChasingDots extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitChasingDots({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 2000), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -17,6 +14,11 @@ class SpinKitChasingDots extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitChasingDotsState createState() => _SpinKitChasingDotsState(); } @@ -25,13 +27,12 @@ class _SpinKitChasingDotsState extends State with TickerProviderStateMixin { AnimationController _scaleCtrl, _rotateCtrl; Animation _scale, _rotate; - final _duration = const Duration(milliseconds: 2000); @override void initState() { super.initState(); - _scaleCtrl = AnimationController(vsync: this, duration: _duration); - _rotateCtrl = AnimationController(vsync: this, duration: _duration); + _scaleCtrl = AnimationController(vsync: this, duration: widget.duration); + _rotateCtrl = AnimationController(vsync: this, duration: widget.duration); _scale = Tween(begin: -1.0, end: 1.0).animate( CurvedAnimation(parent: _scaleCtrl, curve: Curves.easeInOut), diff --git a/lib/src/circle.dart b/lib/src/circle.dart index d75aa9d..d65e378 100644 --- a/lib/src/circle.dart +++ b/lib/src/circle.dart @@ -2,15 +2,12 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitCircle extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitCircle({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +15,11 @@ class SpinKitCircle extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitCircleState createState() => _SpinKitCircleState(); } @@ -29,8 +31,7 @@ class _SpinKitCircleState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)) + _controller = AnimationController(vsync: this, duration: widget.duration) ..repeat(); } diff --git a/lib/src/cube_grid.dart b/lib/src/cube_grid.dart index 3e6fc9c..3d62029 100644 --- a/lib/src/cube_grid.dart +++ b/lib/src/cube_grid.dart @@ -1,22 +1,24 @@ import 'package:flutter/widgets.dart'; class SpinKitCubeGrid extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitCubeGrid({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), 'You should specify either a itemBuilder or a color'), - assert(size != null), + assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitCubeGridState createState() => _SpinKitCubeGridState(); } @@ -29,40 +31,39 @@ class _SpinKitCubeGridState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)); + _controller = AnimationController(vsync: this, duration: widget.duration); _anim1 = Tween(begin: 1.0, end: 0.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.1, 0.6, curve: Curves.easeIn), + curve: const Interval(0.1, 0.6, curve: Curves.easeIn), ), ); _anim2 = Tween(begin: 1.0, end: 0.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.2, 0.7, curve: Curves.easeIn), + curve: const Interval(0.2, 0.7, curve: Curves.easeIn), ), ); _anim3 = Tween(begin: 1.0, end: 0.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.3, 0.8, curve: Curves.easeIn), + curve: const Interval(0.3, 0.8, curve: Curves.easeIn), ), ); _anim4 = Tween(begin: 1.0, end: 0.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.4, 0.9, curve: Curves.easeIn), + curve: const Interval(0.4, 0.9, curve: Curves.easeIn), ), ); _anim5 = Tween(begin: 1.0, end: 0.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.5, 1.0, curve: Curves.easeIn), + curve: const Interval(0.5, 1.0, curve: Curves.easeIn), ), ); @@ -87,9 +88,8 @@ class _SpinKitCubeGridState extends State @override Widget build(BuildContext context) { - return Container( - height: widget.size, - width: widget.size, + return SizedBox.fromSize( + size: Size.square(widget.size), child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, diff --git a/lib/src/double_bounce.dart b/lib/src/double_bounce.dart index 84ead51..94ae2c0 100644 --- a/lib/src/double_bounce.dart +++ b/lib/src/double_bounce.dart @@ -1,22 +1,24 @@ import 'package:flutter/material.dart'; class SpinKitDoubleBounce extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitDoubleBounce({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 2000), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), 'You should specify either a itemBuilder or a color'), - assert(size != null), + assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitDoubleBounceState createState() => _SpinKitDoubleBounceState(); } @@ -38,7 +40,9 @@ class _SpinKitDoubleBounceState extends State void initState() { super.initState(); _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 2000)); + vsync: this, + duration: widget.duration, + ); _animation1 = Tween(begin: -1.0, end: 1.0).animate( CurvedAnimation( diff --git a/lib/src/dual_ring.dart b/lib/src/dual_ring.dart index 693cddf..f81668c 100644 --- a/lib/src/dual_ring.dart +++ b/lib/src/dual_ring.dart @@ -3,17 +3,19 @@ import 'dart:math' as math; import 'package:flutter/widgets.dart'; class SpinKitDualRing extends StatefulWidget { - final Color color; - final double size; - const SpinKitDualRing({ Key key, @required this.color, this.size = 50.0, + this.duration = const Duration(milliseconds: 1200), }) : assert(color != null), assert(size != null), super(key: key); + final Color color; + final double size; + final Duration duration; + @override _SpinKitDualRingState createState() => _SpinKitDualRingState(); } @@ -27,11 +29,13 @@ class _SpinKitDualRingState extends State void initState() { super.initState(); _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)); + vsync: this, + duration: widget.duration, + ); _animation1 = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.0, 1.0, curve: Curves.linear), + curve: const Interval(0.0, 1.0, curve: Curves.linear), ), )..addListener(() => setState(() => {})); @@ -53,9 +57,8 @@ class _SpinKitDualRingState extends State transform: transform, alignment: FractionalOffset.center, child: CustomPaint( - child: Container( - height: widget.size, - width: widget.size, + child: SizedBox.fromSize( + size: Size.square(widget.size), ), painter: _DualRingPainter(color: widget.color), ), @@ -65,15 +68,15 @@ class _SpinKitDualRingState extends State } class _DualRingPainter extends CustomPainter { - Paint p = Paint(); - final double weight; - _DualRingPainter({this.weight = 90.0, Color color}) { p.color = color; p.strokeWidth = 10.0; p.style = PaintingStyle.stroke; } + Paint p = Paint(); + final double weight; + @override void paint(Canvas canvas, Size size) { canvas.drawArc( diff --git a/lib/src/fading_circle.dart b/lib/src/fading_circle.dart index be2af61..25966db 100644 --- a/lib/src/fading_circle.dart +++ b/lib/src/fading_circle.dart @@ -2,15 +2,12 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitFadingCircle extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitFadingCircle({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +15,11 @@ class SpinKitFadingCircle extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitFadingCircleState createState() => _SpinKitFadingCircleState(); } @@ -29,8 +31,7 @@ class _SpinKitFadingCircleState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)) + _controller = AnimationController(vsync: this, duration: widget.duration) ..repeat(); } diff --git a/lib/src/fading_cube.dart b/lib/src/fading_cube.dart index c9bb648..02eb42b 100644 --- a/lib/src/fading_cube.dart +++ b/lib/src/fading_cube.dart @@ -2,15 +2,12 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitFadingCube extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitFadingCube({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 2400), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +15,11 @@ class SpinKitFadingCube extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitFadingCubeState createState() => _SpinKitFadingCubeState(); } @@ -25,12 +27,11 @@ class SpinKitFadingCube extends StatefulWidget { class _SpinKitFadingCubeState extends State with TickerProviderStateMixin { AnimationController _opacityCtrl; - final _duration = const Duration(milliseconds: 2400); @override void initState() { super.initState(); - _opacityCtrl = AnimationController(vsync: this, duration: _duration) + _opacityCtrl = AnimationController(vsync: this, duration: widget.duration) ..repeat(); } diff --git a/lib/src/fading_four.dart b/lib/src/fading_four.dart index 92903a4..1244c90 100644 --- a/lib/src/fading_four.dart +++ b/lib/src/fading_four.dart @@ -2,17 +2,13 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitFadingFour extends StatefulWidget { - final Color color; - final BoxShape shape; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitFadingFour({ Key key, this.color, this.shape = BoxShape.circle, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -21,6 +17,12 @@ class SpinKitFadingFour extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final BoxShape shape; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitFadingFourState createState() => _SpinKitFadingFourState(); } @@ -32,8 +34,7 @@ class _SpinKitFadingFourState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)) + _controller = AnimationController(vsync: this, duration: widget.duration) ..repeat(); } diff --git a/lib/src/fading_grid.dart b/lib/src/fading_grid.dart index 7be44d4..b4da64e 100644 --- a/lib/src/fading_grid.dart +++ b/lib/src/fading_grid.dart @@ -2,17 +2,13 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitFadingGrid extends StatefulWidget { - final Color color; - final BoxShape shape; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitFadingGrid({ Key key, this.color, this.shape = BoxShape.circle, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -21,6 +17,12 @@ class SpinKitFadingGrid extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final BoxShape shape; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitFadingGridState createState() => _SpinKitFadingGridState(); } @@ -32,8 +34,7 @@ class _SpinKitFadingGridState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)) + _controller = AnimationController(vsync: this, duration: widget.duration) ..repeat(); } @@ -45,9 +46,8 @@ class _SpinKitFadingGridState extends State @override Widget build(BuildContext context) { - return Container( - height: widget.size, - width: widget.size, + return SizedBox.fromSize( + size: Size.square(widget.size), child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, diff --git a/lib/src/folding_cube.dart b/lib/src/folding_cube.dart index 9bed1fb..722211b 100644 --- a/lib/src/folding_cube.dart +++ b/lib/src/folding_cube.dart @@ -1,15 +1,12 @@ import 'package:flutter/widgets.dart'; class SpinKitFoldingCube extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitFoldingCube({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 2400), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -17,6 +14,11 @@ class SpinKitFoldingCube extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitFoldingCubeState createState() => _SpinKitFoldingCubeState(); } @@ -25,12 +27,11 @@ class _SpinKitFoldingCubeState extends State with SingleTickerProviderStateMixin { AnimationController _rotateCtrl; Animation _rotate1, _rotate2, _rotate3, _rotate4; - final _duration = const Duration(milliseconds: 2400); @override void initState() { super.initState(); - _rotateCtrl = AnimationController(vsync: this, duration: _duration); + _rotateCtrl = AnimationController(vsync: this, duration: widget.duration); _rotateCtrl ..addStatusListener((status) { @@ -45,28 +46,28 @@ class _SpinKitFoldingCubeState extends State _rotate1 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _rotateCtrl, - curve: Interval(0.0, 0.25, curve: Curves.easeIn), + curve: const Interval(0.0, 0.25, curve: Curves.easeIn), ), )..addListener(() => setState(() => {})); _rotate2 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _rotateCtrl, - curve: Interval(0.25, 0.5, curve: Curves.easeIn), + curve: const Interval(0.25, 0.5, curve: Curves.easeIn), ), )..addListener(() => setState(() => {})); _rotate3 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _rotateCtrl, - curve: Interval(0.5, 0.75, curve: Curves.easeIn), + curve: const Interval(0.5, 0.75, curve: Curves.easeIn), ), )..addListener(() => setState(() => {})); _rotate4 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _rotateCtrl, - curve: Interval(0.75, 1.0, curve: Curves.easeIn), + curve: const Interval(0.75, 1.0, curve: Curves.easeIn), ), )..addListener(() => setState(() => {})); diff --git a/lib/src/hour_glass.dart b/lib/src/hour_glass.dart index 7f280fc..6ee2dce 100644 --- a/lib/src/hour_glass.dart +++ b/lib/src/hour_glass.dart @@ -3,17 +3,19 @@ import 'dart:math' as math; import 'package:flutter/widgets.dart'; class SpinKitHourGlass extends StatefulWidget { - final Color color; - final double size; - const SpinKitHourGlass({ Key key, @required this.color, this.size = 50.0, + this.duration = const Duration(milliseconds: 1200), }) : assert(color != null), assert(size != null), super(key: key); + final Color color; + final double size; + final Duration duration; + @override _SpinKitHourGlassState createState() => _SpinKitHourGlassState(); } @@ -26,12 +28,11 @@ class _SpinKitHourGlassState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)); + _controller = AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 8.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.0, 1.0, curve: Curves.easeOut), + curve: const Interval(0.0, 1.0, curve: Curves.easeOut), ), )..addListener(() => setState(() => {})); @@ -53,9 +54,8 @@ class _SpinKitHourGlassState extends State transform: transform, alignment: FractionalOffset.center, child: CustomPaint( - child: Container( - height: widget.size, - width: widget.size, + child: SizedBox.fromSize( + size: Size.square(widget.size), ), painter: _HourGlassPainter(color: widget.color), ), @@ -65,14 +65,14 @@ class _SpinKitHourGlassState extends State } class _HourGlassPainter extends CustomPainter { - Paint p = Paint(); - final double weight; - _HourGlassPainter({this.weight = 90.0, Color color}) { p.color = color; p.strokeWidth = 1.0; } + Paint p = Paint(); + final double weight; + @override void paint(Canvas canvas, Size size) { canvas.drawArc( diff --git a/lib/src/pouring_hour_glass.dart b/lib/src/pouring_hour_glass.dart index 823f723..409dd50 100644 --- a/lib/src/pouring_hour_glass.dart +++ b/lib/src/pouring_hour_glass.dart @@ -4,17 +4,19 @@ import 'dart:ui'; import 'package:flutter/widgets.dart'; class SpinKitPouringHourglass extends StatefulWidget { - final double size; - final Color color; - const SpinKitPouringHourglass({ Key key, @required this.color, this.size = 50.0, + this.duration = const Duration(milliseconds: 2400), }) : assert(color != null), assert(size != null), super(key: key); + final double size; + final Color color; + final Duration duration; + @override _SpinKitPouringHourglassState createState() => _SpinKitPouringHourglassState(); @@ -32,16 +34,16 @@ class _SpinKitPouringHourglassState extends State super.initState(); _controller = AnimationController( vsync: this, - duration: Duration(milliseconds: 2400), + duration: widget.duration, ); _pouringAnimation = CurvedAnimation( parent: _controller, - curve: Interval(0.0, 0.9), + curve: const Interval(0.0, 0.9), )..addListener(_repaint); _rotationAnimation = Tween(begin: 0.0, end: 0.5).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.9, 1.0, curve: Curves.fastOutSlowIn), + curve: const Interval(0.9, 1.0, curve: Curves.fastOutSlowIn), ), )..addListener(_repaint); _controller.repeat(); @@ -49,8 +51,8 @@ class _SpinKitPouringHourglassState extends State @override void dispose() { - super.dispose(); _controller.dispose(); + super.dispose(); } @override @@ -58,10 +60,8 @@ class _SpinKitPouringHourglassState extends State return Center( child: RotationTransition( turns: _rotationAnimation, - child: Container( - // to avoid painting outside of the box - width: widget.size * math.sqrt1_2, - height: widget.size * math.sqrt1_2, + child: SizedBox.fromSize( + size: Size.square(widget.size * math.sqrt1_2), child: CustomPaint( painter: _HourGlassPaint( poured: _pouringAnimation.value, @@ -77,12 +77,6 @@ class _SpinKitPouringHourglassState extends State } class _HourGlassPaint extends CustomPainter { - final double poured; - - final Paint _paint; - - final Paint _powderPaint; - _HourGlassPaint({ this.poured, @required Color color, @@ -93,6 +87,10 @@ class _HourGlassPaint extends CustomPainter { ..style = PaintingStyle.fill ..color = color; + final double poured; + final Paint _paint; + final Paint _powderPaint; + @override void paint(Canvas canvas, Size size) { final centerX = size.width / 2; diff --git a/lib/src/pulse.dart b/lib/src/pulse.dart index e7ad557..7b20993 100644 --- a/lib/src/pulse.dart +++ b/lib/src/pulse.dart @@ -1,15 +1,12 @@ import 'package:flutter/material.dart'; class SpinKitPulse extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitPulse({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(seconds: 1), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -17,6 +14,11 @@ class SpinKitPulse extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitPulseState createState() => _SpinKitPulseState(); } @@ -29,8 +31,7 @@ class _SpinKitPulseState extends State @override void initState() { super.initState(); - _controller = - AnimationController(vsync: this, duration: Duration(seconds: 1)); + _controller = AnimationController(vsync: this, duration: widget.duration); _animation = CurveTween(curve: Curves.easeInOut).animate(_controller) ..addListener( () => setState(() => {}), diff --git a/lib/src/pumping_heart.dart b/lib/src/pumping_heart.dart index bffe4b2..6fe8a38 100644 --- a/lib/src/pumping_heart.dart +++ b/lib/src/pumping_heart.dart @@ -4,15 +4,12 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; class SpinKitPumpingHeart extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitPumpingHeart({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 2400), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -20,6 +17,11 @@ class SpinKitPumpingHeart extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitPumpingHeartState createState() => _SpinKitPumpingHeartState(); } @@ -32,13 +34,11 @@ class _SpinKitPumpingHeartState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, - duration: Duration(milliseconds: 2400), - )..repeat(); + _controller = AnimationController(vsync: this, duration: widget.duration) + ..repeat(); _anim1 = Tween(begin: 1.0, end: 1.25).animate(CurvedAnimation( parent: _controller, - curve: Interval(0.0, 1.0, curve: MyCurve()), + curve: const Interval(0.0, 1.0, curve: MyCurve()), )); } @@ -68,6 +68,8 @@ class _SpinKitPumpingHeartState extends State } class MyCurve extends Curve { + const MyCurve(); + @override double transform(double t) { if (t >= 0.0 && t < 0.22) { diff --git a/lib/src/ring.dart b/lib/src/ring.dart index d87c991..9f6fe54 100644 --- a/lib/src/ring.dart +++ b/lib/src/ring.dart @@ -3,20 +3,22 @@ import 'dart:math'; import 'package:flutter/widgets.dart'; class SpinKitRing extends StatefulWidget { - final Color color; - final double size; - final double lineWidth; - const SpinKitRing({ Key key, @required this.color, this.lineWidth = 7.0, this.size = 50.0, + this.duration = const Duration(milliseconds: 1200), }) : assert(color != null), assert(lineWidth != null), assert(size != null), super(key: key); + final Color color; + final double size; + final double lineWidth; + final Duration duration; + @override _SpinKitRingState createState() => _SpinKitRingState(); } @@ -29,26 +31,25 @@ class _SpinKitRingState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1500)); + _controller = AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.0, 1.0, curve: Curves.linear), + curve: const Interval(0.0, 1.0, curve: Curves.linear), ), )..addListener(() => setState(() => {})); _animation2 = Tween(begin: -2 / 3, end: 1 / 2).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.5, 1.0, curve: Curves.linear), + curve: const Interval(0.5, 1.0, curve: Curves.linear), ), )..addListener(() => setState(() => {})); _animation3 = Tween(begin: 0.25, end: 5 / 6).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.0, 1.0, curve: _MyCurve()), + curve: const Interval(0.0, 1.0, curve: _MyCurve()), ), )..addListener(() => setState(() => {})); @@ -69,9 +70,8 @@ class _SpinKitRingState extends State child: Transform( transform: transform, alignment: FractionalOffset.center, - child: Container( - height: widget.size, - width: widget.size, + child: SizedBox.fromSize( + size: Size.square(widget.size), child: CustomPaint( foregroundPainter: RingPainter( paintWidth: widget.lineWidth, @@ -87,12 +87,6 @@ class _SpinKitRingState extends State } class RingPainter extends CustomPainter { - final double paintWidth; - final Paint trackPaint; - final Color trackColor; - final double progressPercent; - final double startAngle; - RingPainter({ this.paintWidth, this.progressPercent, @@ -104,6 +98,12 @@ class RingPainter extends CustomPainter { ..strokeWidth = paintWidth ..strokeCap = StrokeCap.square; + final double paintWidth; + final Paint trackPaint; + final Color trackColor; + final double progressPercent; + final double startAngle; + @override void paint(Canvas canvas, Size size) { final center = Offset(size.width / 2, size.height / 2); @@ -112,14 +112,15 @@ class RingPainter extends CustomPainter { final progressAngle = 2 * pi * progressPercent; canvas.drawArc( - Rect.fromCircle( - center: center, - radius: radius, - ), - startAngle, - progressAngle, - false, - trackPaint); + Rect.fromCircle( + center: center, + radius: radius, + ), + startAngle, + progressAngle, + false, + trackPaint, + ); } @override @@ -129,6 +130,8 @@ class RingPainter extends CustomPainter { } class _MyCurve extends Curve { + const _MyCurve(); + @override double transform(double t) { if (t <= 0.5) { diff --git a/lib/src/ripple.dart b/lib/src/ripple.dart index 24d8ddb..c3ea469 100644 --- a/lib/src/ripple.dart +++ b/lib/src/ripple.dart @@ -1,17 +1,13 @@ import 'package:flutter/material.dart'; class SpinKitRipple extends StatefulWidget { - final Color color; - final double size; - final double borderWidth; - final IndexedWidgetBuilder itemBuilder; - SpinKitRipple({ Key key, this.color, this.size = 50.0, this.borderWidth = 6.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1800), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -20,6 +16,12 @@ class SpinKitRipple extends StatefulWidget { assert(borderWidth != null), super(key: key); + final Color color; + final double size; + final double borderWidth; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitRippleState createState() => _SpinKitRippleState(); } @@ -32,21 +34,20 @@ class _SpinKitRippleState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1800)) + _controller = AnimationController(vsync: this, duration: widget.duration) ..repeat(); _animation1 = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.0, 0.75, curve: Curves.linear), + curve: const Interval(0.0, 0.75, curve: Curves.linear), ), )..addListener(() => setState(() => {})); _animation2 = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.25, 1.0, curve: Curves.linear), + curve: const Interval(0.25, 1.0, curve: Curves.linear), ), )..addListener(() => setState(() => {})); } diff --git a/lib/src/rotating_circle.dart b/lib/src/rotating_circle.dart index c5602a3..4cbe2af 100644 --- a/lib/src/rotating_circle.dart +++ b/lib/src/rotating_circle.dart @@ -1,15 +1,12 @@ import 'package:flutter/widgets.dart'; class SpinKitRotatingCircle extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitRotatingCircle({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -17,9 +14,13 @@ class SpinKitRotatingCircle extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override - _SpinKitRotatingCircleState createState() => - _SpinKitRotatingCircleState(); + _SpinKitRotatingCircleState createState() => _SpinKitRotatingCircleState(); } class _SpinKitRotatingCircleState extends State @@ -31,19 +32,18 @@ class _SpinKitRotatingCircleState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)); + _controller = AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.0, 0.5, curve: Curves.easeIn), + curve: const Interval(0.0, 0.5, curve: Curves.easeIn), ), )..addListener(() => setState(() => {})); _animation2 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.5, 1.0, curve: Curves.easeOut), + curve: const Interval(0.5, 1.0, curve: Curves.easeOut), ), )..addListener(() => setState(() => {})); diff --git a/lib/src/rotating_plain.dart b/lib/src/rotating_plain.dart index 61f859f..bed6705 100644 --- a/lib/src/rotating_plain.dart +++ b/lib/src/rotating_plain.dart @@ -1,15 +1,12 @@ import 'package:flutter/widgets.dart'; class SpinKitRotatingPlain extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitRotatingPlain({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -17,6 +14,11 @@ class SpinKitRotatingPlain extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitRotatingPlainState createState() => _SpinKitRotatingPlainState(); } @@ -30,19 +32,18 @@ class _SpinKitRotatingPlainState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)); + _controller = AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.0, 0.5, curve: Curves.easeIn), + curve: const Interval(0.0, 0.5, curve: Curves.easeIn), ), )..addListener(() => setState(() => {})); _animation2 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.5, 1.0, curve: Curves.easeOut), + curve: const Interval(0.5, 1.0, curve: Curves.easeOut), ), )..addListener(() => setState(() => {})); diff --git a/lib/src/spinning_circle.dart b/lib/src/spinning_circle.dart index 17473f2..91b45fe 100644 --- a/lib/src/spinning_circle.dart +++ b/lib/src/spinning_circle.dart @@ -3,17 +3,13 @@ import 'dart:math'; import 'package:flutter/widgets.dart'; class SpinKitSpinningCircle extends StatefulWidget { - final Color color; - final BoxShape shape; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitSpinningCircle({ Key key, this.color, this.shape = BoxShape.circle, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -22,9 +18,14 @@ class SpinKitSpinningCircle extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final BoxShape shape; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override - _SpinKitSpinningCircleState createState() => - _SpinKitSpinningCircleState(); + _SpinKitSpinningCircleState createState() => _SpinKitSpinningCircleState(); } class _SpinKitSpinningCircleState extends State @@ -35,12 +36,11 @@ class _SpinKitSpinningCircleState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, duration: Duration(milliseconds: 1200)); + _controller = AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 7.0).animate( CurvedAnimation( parent: _controller, - curve: Interval(0.0, 1.0, curve: Curves.easeOut), + curve: const Interval(0.0, 1.0, curve: Curves.easeOut), ), )..addListener(() => setState(() => {})); diff --git a/lib/src/three_bounce.dart b/lib/src/three_bounce.dart index 19e8eec..f918a66 100644 --- a/lib/src/three_bounce.dart +++ b/lib/src/three_bounce.dart @@ -2,15 +2,12 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitThreeBounce extends StatefulWidget { - final Color color; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitThreeBounce({ Key key, this.color, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1400), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +15,11 @@ class SpinKitThreeBounce extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitThreeBounceState createState() => _SpinKitThreeBounceState(); } @@ -25,15 +27,12 @@ class SpinKitThreeBounce extends StatefulWidget { class _SpinKitThreeBounceState extends State with SingleTickerProviderStateMixin { AnimationController _scaleCtrl; - final _duration = const Duration(milliseconds: 1400); @override void initState() { super.initState(); - _scaleCtrl = AnimationController( - vsync: this, - duration: _duration, - )..repeat(); + _scaleCtrl = AnimationController(vsync: this, duration: widget.duration) + ..repeat(); } @override @@ -62,8 +61,7 @@ class _SpinKitThreeBounceState extends State Widget _circle(int index, double delay) { final _size = widget.size * 0.5; return ScaleTransition( - scale: DelayTween(begin: 0.0, end: 1.0, delay: delay) - .animate(_scaleCtrl), + scale: DelayTween(begin: 0.0, end: 1.0, delay: delay).animate(_scaleCtrl), child: SizedBox.fromSize( size: Size.square(_size), child: _itemBuilder(index), diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 9873664..acc38de 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -3,14 +3,14 @@ import 'dart:math' as math show sin, pi; import 'package:flutter/widgets.dart'; class DelayTween extends Tween { - final double delay; - DelayTween({ double begin, double end, this.delay, }) : super(begin: begin, end: end); + final double delay; + @override double lerp(double t) { return super.lerp((math.sin((t - delay) * 2 * math.pi) + 1) / 2); @@ -21,14 +21,14 @@ class DelayTween extends Tween { } class AngleDelayTween extends Tween { - final double delay; - AngleDelayTween({ double begin, double end, this.delay, }) : super(begin: begin, end: end); + final double delay; + @override double lerp(double t) => super.lerp(math.sin((t - delay) * math.pi * 0.5)); diff --git a/lib/src/wandering_cubes.dart b/lib/src/wandering_cubes.dart index 7fe44ce..3cc6088 100644 --- a/lib/src/wandering_cubes.dart +++ b/lib/src/wandering_cubes.dart @@ -1,17 +1,13 @@ import 'package:flutter/material.dart'; class SpinKitWanderingCubes extends StatefulWidget { - final Color color; - final BoxShape shape; - final double size; - final IndexedWidgetBuilder itemBuilder; - SpinKitWanderingCubes({ Key key, this.color, this.shape = BoxShape.rectangle, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1800), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -20,9 +16,14 @@ class SpinKitWanderingCubes extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final BoxShape shape; + final double size; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override - _SpinKitWanderingCubesState createState() => - _SpinKitWanderingCubesState(); + _SpinKitWanderingCubesState createState() => _SpinKitWanderingCubesState(); } class _SpinKitWanderingCubesState extends State @@ -30,37 +31,37 @@ class _SpinKitWanderingCubesState extends State AnimationController _scaleCtrl, _rotateCtrl, _translateCtrl; Animation _scale1, _scale2, _scale3, _scale4, _rotate; Animation _translate1, _translate2, _translate3, _translate4; - final _duration = const Duration(milliseconds: 1800); double _offset; void initTranslateAnim() { - _translateCtrl = AnimationController(vsync: this, duration: _duration); + _translateCtrl = + AnimationController(vsync: this, duration: widget.duration); _translate1 = Tween(begin: 0.0, end: _offset).animate( CurvedAnimation( parent: _translateCtrl, - curve: Interval(0.0, 0.25, curve: Curves.easeInOut), + curve: const Interval(0.0, 0.25, curve: Curves.easeInOut), ), )..addListener(() => setState(() => {})); _translate2 = Tween(begin: 0.0, end: _offset).animate( CurvedAnimation( parent: _translateCtrl, - curve: Interval(0.25, 0.5, curve: Curves.easeInOut), + curve: const Interval(0.25, 0.5, curve: Curves.easeInOut), ), )..addListener(() => setState(() => {})); _translate3 = Tween(begin: 0.0, end: -_offset).animate( CurvedAnimation( parent: _translateCtrl, - curve: Interval(0.5, 0.75, curve: Curves.easeInOut), + curve: const Interval(0.5, 0.75, curve: Curves.easeInOut), ), )..addListener(() => setState(() => {})); _translate4 = Tween(begin: 0.0, end: -_offset).animate( CurvedAnimation( parent: _translateCtrl, - curve: Interval(0.75, 1.0, curve: Curves.easeInOut), + curve: const Interval(0.75, 1.0, curve: Curves.easeInOut), ), )..addListener(() => setState(() => {})); @@ -68,33 +69,33 @@ class _SpinKitWanderingCubesState extends State } void initScaleAnim() { - _scaleCtrl = AnimationController(vsync: this, duration: _duration); + _scaleCtrl = AnimationController(vsync: this, duration: widget.duration); _scale1 = Tween(begin: 1.0, end: 0.5).animate( CurvedAnimation( parent: _scaleCtrl, - curve: Interval(0.0, 0.25, curve: Curves.easeInOut), + curve: const Interval(0.0, 0.25, curve: Curves.easeInOut), ), )..addListener(() => setState(() => {})); _scale2 = Tween(begin: 1.0, end: 2.0).animate( CurvedAnimation( parent: _scaleCtrl, - curve: Interval(0.25, 0.5, curve: Curves.easeInOut), + curve: const Interval(0.25, 0.5, curve: Curves.easeInOut), ), )..addListener(() => setState(() => {})); _scale3 = Tween(begin: 1.0, end: 0.5).animate( CurvedAnimation( parent: _scaleCtrl, - curve: Interval(0.5, 0.75, curve: Curves.easeInOut), + curve: const Interval(0.5, 0.75, curve: Curves.easeInOut), ), )..addListener(() => setState(() => {})); _scale4 = Tween(begin: 1.0, end: 2.0).animate( CurvedAnimation( parent: _scaleCtrl, - curve: Interval(0.75, 1.0, curve: Curves.easeInOut), + curve: const Interval(0.75, 1.0, curve: Curves.easeInOut), ), )..addListener(() => setState(() => {})); @@ -109,7 +110,7 @@ class _SpinKitWanderingCubesState extends State initTranslateAnim(); initScaleAnim(); - _rotateCtrl = AnimationController(vsync: this, duration: _duration); + _rotateCtrl = AnimationController(vsync: this, duration: widget.duration); _rotate = Tween(begin: 0.0, end: 360.0).animate( CurvedAnimation(parent: _translateCtrl, curve: Curves.linear), diff --git a/lib/src/wave.dart b/lib/src/wave.dart index 26f5d27..764145a 100644 --- a/lib/src/wave.dart +++ b/lib/src/wave.dart @@ -4,17 +4,13 @@ import 'package:flutter_spinkit/src/utils.dart'; enum SpinKitWaveType { start, end, center } class SpinKitWave extends StatefulWidget { - final Color color; - final double size; - final SpinKitWaveType type; - final IndexedWidgetBuilder itemBuilder; - SpinKitWave({ Key key, this.color, this.type = SpinKitWaveType.start, this.size = 50.0, this.itemBuilder, + this.duration = const Duration(milliseconds: 1200), }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -23,6 +19,12 @@ class SpinKitWave extends StatefulWidget { assert(size != null), super(key: key); + final Color color; + final double size; + final SpinKitWaveType type; + final IndexedWidgetBuilder itemBuilder; + final Duration duration; + @override _SpinKitWaveState createState() => _SpinKitWaveState(); } @@ -30,15 +32,12 @@ class SpinKitWave extends StatefulWidget { class _SpinKitWaveState extends State with SingleTickerProviderStateMixin { AnimationController _scaleCtrl; - final _duration = const Duration(milliseconds: 1200); @override void initState() { super.initState(); - _scaleCtrl = AnimationController( - vsync: this, - duration: _duration, - )..repeat(); + _scaleCtrl = AnimationController(vsync: this, duration: widget.duration) + ..repeat(); } @override @@ -113,9 +112,6 @@ class _SpinKitWaveState extends State } class ScaleYWidget extends AnimatedWidget { - final Widget child; - final Alignment alignment; - const ScaleYWidget({ Key key, @required Animation scaleY, @@ -123,13 +119,15 @@ class ScaleYWidget extends AnimatedWidget { this.alignment = Alignment.center, }) : super(key: key, listenable: scaleY); + final Widget child; + final Alignment alignment; + Animation get scaleY => listenable; @override Widget build(BuildContext context) { final double scaleValue = scaleY.value; - final Matrix4 transform = Matrix4.identity() - ..scale(1.0, scaleValue, 1.0); + final Matrix4 transform = Matrix4.identity()..scale(1.0, scaleValue, 1.0); return Transform( transform: transform, alignment: alignment, diff --git a/pubspec.lock b/pubspec.lock index 9b16178..21d16f3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,20 +1,6 @@ # 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.32.4" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.0" async: dependency: transitive description: @@ -43,27 +29,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.2" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.6" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.5" flutter: dependency: "direct main" description: flutter @@ -74,83 +39,6 @@ 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.4" - glob: - dependency: transitive - description: - name: glob - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.7" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.13.3+3" - http: - dependency: transitive - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+17" - http_multi_server: - dependency: transitive - description: - name: http_multi_server - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" - http_parser: - dependency: transitive - description: - name: http_parser - url: "https://pub.dartlang.org" - source: hosted - version: "3.1.3" - io: - dependency: transitive - description: - name: io - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.3" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - 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.9" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.4" - logging: - dependency: transitive - description: - name: logging - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+2" matcher: dependency: transitive description: @@ -165,41 +53,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" - mime: - dependency: transitive - description: - name: mime - url: "https://pub.dartlang.org" - source: hosted - 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.2" - node_preamble: - dependency: transitive - description: - name: node_preamble - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.4" - package_config: - dependency: transitive - description: - name: package_config - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - package_resolver: - dependency: transitive - description: - name: package_resolver - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.4" path: dependency: transitive description: @@ -207,81 +60,18 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.2" - plugin: - dependency: transitive - description: - name: plugin - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0+3" - pool: - dependency: transitive - description: - name: pool - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.6" - pub_semver: - dependency: transitive - description: - name: pub_semver - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.2" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.0+1" - shelf: - dependency: transitive - description: - name: shelf - url: "https://pub.dartlang.org" - source: hosted - 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.4" - shelf_static: - dependency: transitive - description: - name: shelf_static - url: "https://pub.dartlang.org" - source: hosted - 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+4" + 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.5" - source_maps: - dependency: transitive - description: - name: source_maps - url: "https://pub.dartlang.org" - source: hosted - version: "0.10.7" source_span: dependency: transitive description: @@ -317,13 +107,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.1" - test: + test_api: dependency: transitive description: - name: test + name: test_api url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "0.2.1" typed_data: dependency: transitive description: @@ -331,13 +121,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" - utf: - dependency: transitive - description: - name: utf - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.0+5" vector_math: dependency: transitive description: @@ -345,34 +128,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" - vm_service_client: - dependency: transitive - description: - name: vm_service_client - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.6" - watcher: - dependency: transitive - description: - name: watcher - url: "https://pub.dartlang.org" - source: hosted - 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.9" - yaml: - dependency: transitive - description: - name: yaml - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.15" sdks: - dart: ">=2.0.0-dev.68.0 <3.0.0" + dart: ">=2.0.0 <3.0.0" flutter: ">=0.1.4 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 5b72bb5..2e93cd2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_spinkit description: A collection of loading indicators animated with flutter. Heavily inspired by @tobiasahlin's SpinKit. -version: 3.0.0 +version: 3.1.0 homepage: https://github.com/jogboms/flutter_spinkit authors: