diff --git a/CHANGELOG.md b/CHANGELOG.md index a722af0..e7e0b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,27 @@ A collection of loading indicators animated with flutter. Heavily inspired by @tobiasahlin's SpinKit. +## 4.0.0 + +### Feature + +- `controller` parameter [20248d](https://github.com/jogboms/flutter_spinkit/commit/20248d2f8bd1056a453a5e57f063e8d59dba9b36). Closes [#51](https://github.com/jogboms/flutter_spinkit/issues/51) + +```dart +SpinKitFadingCircle( + color: Colors.white, + size: 50.0, + controller: AnimationController(vsync: this, duration: const Duration(milliseconds: 1200)), +); + +``` +- DualRing `lineWidth` parameter [5873e7](https://github.com/jogboms/flutter_spinkit/commit/5873e75430aca52d2ec0c483dcd71a02438f3e8b). Closes [#42](https://github.com/jogboms/flutter_spinkit/issues/42) + ## 3.1.0 ### Feature -- duration parameter [70b113b](https://github.com/jogboms/flutter_spinkit/commit/70b113b384200e344336d521704a1c96d2864909) +- `duration` parameter [70b113b](https://github.com/jogboms/flutter_spinkit/commit/70b113b384200e344336d521704a1c96d2864909) ### Fixes diff --git a/README.md b/README.md index 4732e71..cb9e332 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.1.0" + flutter_spinkit: "^4.0.0" ``` ### ⚡️ Import @@ -26,8 +26,6 @@ SpinKitRotatingCircle( ); ``` -#### As from 3.0.0 - ```dart SpinKitFadingCircle( itemBuilder: (_, int index) { @@ -40,13 +38,19 @@ SpinKitFadingCircle( ); ``` -#### Which produces +#### As from 4.0.0 - +```dart +SpinKitFadingCircle( + color: Colors.white, + size: 50.0, + controller: AnimationController(vsync: this, duration: const Duration(milliseconds: 1200)), +); +``` For more info, please, refer to the `showcase.dart` in the example. -## 🚀 Roadmap +## 🚀 Showcase diff --git a/analysis_options.yaml b/analysis_options.yaml index 1221796..5ed654a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -110,7 +110,6 @@ linter: # - parameter_assignments # we do this commonly - prefer_adjacent_string_concatenation - prefer_asserts_in_initializer_lists - - prefer_bool_in_asserts - prefer_collection_literals - prefer_conditional_assignment # - prefer_const_constructors @@ -135,7 +134,6 @@ linter: - slash_for_doc_comments - sort_constructors_first - sort_unnamed_constructors_first - - super_goes_last - test_types_in_equals - throw_in_finally # - type_annotate_public_apis # subset of always_specify_types diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index cf91f07..a9aca1e 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -41,7 +40,6 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; @@ -74,7 +72,6 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEBA1CF902C7004384FC /* Flutter.framework */, @@ -192,7 +189,6 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/example/pubspec.lock b/example/pubspec.lock index b5fea75..e8fefe9 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.2.0" boolean_selector: dependency: transitive description: @@ -40,7 +40,7 @@ packages: path: ".." relative: true source: path - version: "3.1.0" + version: "4.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -52,7 +52,7 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.5" meta: dependency: transitive description: @@ -67,13 +67,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.2" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.3" sky_engine: dependency: transitive description: flutter @@ -85,7 +92,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.5.5" stack_trace: dependency: transitive description: @@ -99,7 +106,7 @@ packages: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.0.0" string_scanner: dependency: transitive description: @@ -113,14 +120,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "0.2.5" typed_data: dependency: transitive description: @@ -136,5 +143,5 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.0.0 <3.0.0" + dart: ">=2.2.2 <3.0.0" flutter: ">=0.1.4 <2.0.0" diff --git a/flutter_spinkit.iml b/flutter_spinkit.iml index 8d48a06..70b4a9b 100644 --- a/flutter_spinkit.iml +++ b/flutter_spinkit.iml @@ -9,6 +9,9 @@ + + + diff --git a/lib/src/chasing_dots.dart b/lib/src/chasing_dots.dart index dbd4643..55da72b 100644 --- a/lib/src/chasing_dots.dart +++ b/lib/src/chasing_dots.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; class SpinKitChasingDots extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitChasingDots({ Key key, this.color, @@ -37,7 +38,7 @@ class _SpinKitChasingDotsState extends State _scale = Tween(begin: -1.0, end: 1.0).animate( CurvedAnimation(parent: _scaleCtrl, curve: Curves.easeInOut), ) - ..addListener(() => setState(() => {})) + ..addListener(() => setState(() {})) ..addStatusListener((status) { if (status == AnimationStatus.completed) { _scaleCtrl.reverse(); @@ -48,7 +49,7 @@ class _SpinKitChasingDotsState extends State _rotate = Tween(begin: 0.0, end: 360.0).animate( CurvedAnimation(parent: _rotateCtrl, curve: Curves.linear), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _rotateCtrl.repeat(); _scaleCtrl.forward(); diff --git a/lib/src/circle.dart b/lib/src/circle.dart index d65e378..150b5f8 100644 --- a/lib/src/circle.dart +++ b/lib/src/circle.dart @@ -2,12 +2,14 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitCircle extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitCircle({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -19,6 +21,7 @@ class SpinKitCircle extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitCircleState createState() => _SpinKitCircleState(); @@ -31,7 +34,8 @@ class _SpinKitCircleState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration) + _controller = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); } diff --git a/lib/src/cube_grid.dart b/lib/src/cube_grid.dart index 3d62029..ed5225f 100644 --- a/lib/src/cube_grid.dart +++ b/lib/src/cube_grid.dart @@ -1,12 +1,14 @@ import 'package:flutter/widgets.dart'; class SpinKitCubeGrid extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitCubeGrid({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +20,7 @@ class SpinKitCubeGrid extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitCubeGridState createState() => _SpinKitCubeGridState(); @@ -31,7 +34,8 @@ class _SpinKitCubeGridState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _anim1 = Tween(begin: 1.0, end: 0.0).animate( CurvedAnimation( parent: _controller, diff --git a/lib/src/double_bounce.dart b/lib/src/double_bounce.dart index 94ae2c0..966e0a8 100644 --- a/lib/src/double_bounce.dart +++ b/lib/src/double_bounce.dart @@ -1,12 +1,14 @@ import 'package:flutter/material.dart'; class SpinKitDoubleBounce extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitDoubleBounce({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 2000), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +20,7 @@ class SpinKitDoubleBounce extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitDoubleBounceState createState() => _SpinKitDoubleBounceState(); @@ -39,10 +42,8 @@ class _SpinKitDoubleBounceState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, - duration: widget.duration, - ); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: -1.0, end: 1.0).animate( CurvedAnimation( @@ -50,7 +51,7 @@ class _SpinKitDoubleBounceState extends State curve: Curves.easeInOut, ), ) - ..addListener(() => setState(() => {})) + ..addListener(() => setState(() {})) ..addStatusListener(_statusListener); _controller.forward(); diff --git a/lib/src/dual_ring.dart b/lib/src/dual_ring.dart index f81668c..85f4692 100644 --- a/lib/src/dual_ring.dart +++ b/lib/src/dual_ring.dart @@ -3,18 +3,23 @@ import 'dart:math' as math; import 'package:flutter/widgets.dart'; class SpinKitDualRing extends StatefulWidget { - const SpinKitDualRing({ + // ignore: prefer_const_constructors_in_immutables + SpinKitDualRing({ Key key, @required this.color, + this.lineWidth = 7.0, this.size = 50.0, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert(color != null), assert(size != null), super(key: key); final Color color; + final double lineWidth; final double size; final Duration duration; + final AnimationController controller; @override _SpinKitDualRingState createState() => _SpinKitDualRingState(); @@ -28,16 +33,14 @@ class _SpinKitDualRingState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, - duration: widget.duration, - ); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.0, 1.0, curve: Curves.linear), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _controller.repeat(); } @@ -60,7 +63,10 @@ class _SpinKitDualRingState extends State child: SizedBox.fromSize( size: Size.square(widget.size), ), - painter: _DualRingPainter(color: widget.color), + painter: _DualRingPainter( + paintWidth: widget.lineWidth, + color: widget.color, + ), ), ), ); @@ -68,31 +74,23 @@ class _SpinKitDualRingState extends State } class _DualRingPainter extends CustomPainter { - _DualRingPainter({this.weight = 90.0, Color color}) { - p.color = color; - p.strokeWidth = 10.0; - p.style = PaintingStyle.stroke; - } + _DualRingPainter({ + this.angle = 90.0, + double paintWidth, + Color color, + }) : ringPaint = Paint() + ..color = color + ..strokeWidth = paintWidth + ..style = PaintingStyle.stroke; - Paint p = Paint(); - final double weight; + final Paint ringPaint; + final double angle; @override void paint(Canvas canvas, Size size) { - canvas.drawArc( - Rect.fromPoints(Offset.zero, Offset(size.width, size.height)), - 0.0, - getRadian(weight), - false, - p, - ); - canvas.drawArc( - Rect.fromPoints(Offset.zero, Offset(size.width, size.height)), - getRadian(180.0), - getRadian(weight), - false, - p, - ); + final rect = Rect.fromPoints(Offset.zero, Offset(size.width, size.height)); + canvas.drawArc(rect, 0.0, getRadian(angle), false, ringPaint); + canvas.drawArc(rect, getRadian(180.0), getRadian(angle), false, ringPaint); } @override diff --git a/lib/src/fading_circle.dart b/lib/src/fading_circle.dart index 25966db..25553e2 100644 --- a/lib/src/fading_circle.dart +++ b/lib/src/fading_circle.dart @@ -2,12 +2,14 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitFadingCircle extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitFadingCircle({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -19,6 +21,7 @@ class SpinKitFadingCircle extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitFadingCircleState createState() => _SpinKitFadingCircleState(); @@ -31,7 +34,8 @@ class _SpinKitFadingCircleState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration) + _controller = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); } diff --git a/lib/src/fading_cube.dart b/lib/src/fading_cube.dart index 02eb42b..104440d 100644 --- a/lib/src/fading_cube.dart +++ b/lib/src/fading_cube.dart @@ -2,12 +2,14 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitFadingCube extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitFadingCube({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 2400), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -19,6 +21,7 @@ class SpinKitFadingCube extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitFadingCubeState createState() => _SpinKitFadingCubeState(); @@ -31,7 +34,8 @@ class _SpinKitFadingCubeState extends State @override void initState() { super.initState(); - _opacityCtrl = AnimationController(vsync: this, duration: widget.duration) + _opacityCtrl = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); } diff --git a/lib/src/fading_four.dart b/lib/src/fading_four.dart index 1244c90..6c6b12c 100644 --- a/lib/src/fading_four.dart +++ b/lib/src/fading_four.dart @@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitFadingFour extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitFadingFour({ Key key, this.color, @@ -9,6 +10,7 @@ class SpinKitFadingFour extends StatefulWidget { this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -22,6 +24,7 @@ class SpinKitFadingFour extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitFadingFourState createState() => _SpinKitFadingFourState(); @@ -34,7 +37,8 @@ class _SpinKitFadingFourState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration) + _controller = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); } diff --git a/lib/src/fading_grid.dart b/lib/src/fading_grid.dart index b4da64e..aa2d6fa 100644 --- a/lib/src/fading_grid.dart +++ b/lib/src/fading_grid.dart @@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitFadingGrid extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitFadingGrid({ Key key, this.color, @@ -9,6 +10,7 @@ class SpinKitFadingGrid extends StatefulWidget { this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -22,6 +24,7 @@ class SpinKitFadingGrid extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitFadingGridState createState() => _SpinKitFadingGridState(); @@ -34,7 +37,8 @@ class _SpinKitFadingGridState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration) + _controller = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); } diff --git a/lib/src/folding_cube.dart b/lib/src/folding_cube.dart index 722211b..dd1358d 100644 --- a/lib/src/folding_cube.dart +++ b/lib/src/folding_cube.dart @@ -1,12 +1,14 @@ import 'package:flutter/widgets.dart'; class SpinKitFoldingCube extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitFoldingCube({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 2400), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +20,7 @@ class SpinKitFoldingCube extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitFoldingCubeState createState() => _SpinKitFoldingCubeState(); @@ -31,7 +34,8 @@ class _SpinKitFoldingCubeState extends State @override void initState() { super.initState(); - _rotateCtrl = AnimationController(vsync: this, duration: widget.duration); + _rotateCtrl = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _rotateCtrl ..addStatusListener((status) { @@ -48,28 +52,28 @@ class _SpinKitFoldingCubeState extends State parent: _rotateCtrl, curve: const Interval(0.0, 0.25, curve: Curves.easeIn), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _rotate2 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _rotateCtrl, curve: const Interval(0.25, 0.5, curve: Curves.easeIn), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _rotate3 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _rotateCtrl, curve: const Interval(0.5, 0.75, curve: Curves.easeIn), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _rotate4 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _rotateCtrl, curve: const Interval(0.75, 1.0, curve: Curves.easeIn), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _rotateCtrl.forward(); } diff --git a/lib/src/hour_glass.dart b/lib/src/hour_glass.dart index 6ee2dce..c7fe6c6 100644 --- a/lib/src/hour_glass.dart +++ b/lib/src/hour_glass.dart @@ -8,6 +8,7 @@ class SpinKitHourGlass extends StatefulWidget { @required this.color, this.size = 50.0, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert(color != null), assert(size != null), super(key: key); @@ -15,6 +16,7 @@ class SpinKitHourGlass extends StatefulWidget { final Color color; final double size; final Duration duration; + final AnimationController controller; @override _SpinKitHourGlassState createState() => _SpinKitHourGlassState(); @@ -28,13 +30,14 @@ class _SpinKitHourGlassState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 8.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.0, 1.0, curve: Curves.easeOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _controller.repeat(); } diff --git a/lib/src/pouring_hour_glass.dart b/lib/src/pouring_hour_glass.dart index 409dd50..f103781 100644 --- a/lib/src/pouring_hour_glass.dart +++ b/lib/src/pouring_hour_glass.dart @@ -9,6 +9,7 @@ class SpinKitPouringHourglass extends StatefulWidget { @required this.color, this.size = 50.0, this.duration = const Duration(milliseconds: 2400), + this.controller, }) : assert(color != null), assert(size != null), super(key: key); @@ -16,6 +17,7 @@ class SpinKitPouringHourglass extends StatefulWidget { final double size; final Color color; final Duration duration; + final AnimationController controller; @override _SpinKitPouringHourglassState createState() => @@ -32,10 +34,8 @@ class _SpinKitPouringHourglassState extends State @override void initState() { super.initState(); - _controller = AnimationController( - vsync: this, - duration: widget.duration, - ); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _pouringAnimation = CurvedAnimation( parent: _controller, curve: const Interval(0.0, 0.9), diff --git a/lib/src/pulse.dart b/lib/src/pulse.dart index 7b20993..b2308f7 100644 --- a/lib/src/pulse.dart +++ b/lib/src/pulse.dart @@ -1,12 +1,14 @@ import 'package:flutter/material.dart'; class SpinKitPulse extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitPulse({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(seconds: 1), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +20,7 @@ class SpinKitPulse extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitPulseState createState() => _SpinKitPulseState(); @@ -31,10 +34,11 @@ class _SpinKitPulseState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _animation = CurveTween(curve: Curves.easeInOut).animate(_controller) ..addListener( - () => setState(() => {}), + () => setState(() {}), ); _controller.repeat(); diff --git a/lib/src/pumping_heart.dart b/lib/src/pumping_heart.dart index 6fe8a38..e468134 100644 --- a/lib/src/pumping_heart.dart +++ b/lib/src/pumping_heart.dart @@ -4,12 +4,14 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; class SpinKitPumpingHeart extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitPumpingHeart({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 2400), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -21,6 +23,7 @@ class SpinKitPumpingHeart extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitPumpingHeartState createState() => _SpinKitPumpingHeartState(); @@ -34,7 +37,8 @@ class _SpinKitPumpingHeartState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration) + _controller = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); _anim1 = Tween(begin: 1.0, end: 1.25).animate(CurvedAnimation( parent: _controller, diff --git a/lib/src/ring.dart b/lib/src/ring.dart index 9f6fe54..8957ace 100644 --- a/lib/src/ring.dart +++ b/lib/src/ring.dart @@ -9,6 +9,7 @@ class SpinKitRing extends StatefulWidget { this.lineWidth = 7.0, this.size = 50.0, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert(color != null), assert(lineWidth != null), assert(size != null), @@ -18,6 +19,7 @@ class SpinKitRing extends StatefulWidget { final double size; final double lineWidth; final Duration duration; + final AnimationController controller; @override _SpinKitRingState createState() => _SpinKitRingState(); @@ -31,27 +33,28 @@ class _SpinKitRingState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.0, 1.0, curve: Curves.linear), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _animation2 = Tween(begin: -2 / 3, end: 1 / 2).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.5, 1.0, curve: Curves.linear), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _animation3 = Tween(begin: 0.25, end: 5 / 6).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.0, 1.0, curve: _MyCurve()), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _controller.repeat(); } diff --git a/lib/src/ripple.dart b/lib/src/ripple.dart index c3ea469..51c9160 100644 --- a/lib/src/ripple.dart +++ b/lib/src/ripple.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; class SpinKitRipple extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitRipple({ Key key, this.color, @@ -8,6 +9,7 @@ class SpinKitRipple extends StatefulWidget { this.borderWidth = 6.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1800), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -21,6 +23,7 @@ class SpinKitRipple extends StatefulWidget { final double borderWidth; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitRippleState createState() => _SpinKitRippleState(); @@ -34,7 +37,8 @@ class _SpinKitRippleState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration) + _controller = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); _animation1 = Tween(begin: 0.0, end: 1.0).animate( @@ -42,14 +46,14 @@ class _SpinKitRippleState extends State parent: _controller, curve: const Interval(0.0, 0.75, curve: Curves.linear), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _animation2 = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.25, 1.0, curve: Curves.linear), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); } @override diff --git a/lib/src/rotating_circle.dart b/lib/src/rotating_circle.dart index 4cbe2af..f565342 100644 --- a/lib/src/rotating_circle.dart +++ b/lib/src/rotating_circle.dart @@ -1,12 +1,14 @@ import 'package:flutter/widgets.dart'; class SpinKitRotatingCircle extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitRotatingCircle({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +20,7 @@ class SpinKitRotatingCircle extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitRotatingCircleState createState() => _SpinKitRotatingCircleState(); @@ -32,20 +35,21 @@ class _SpinKitRotatingCircleState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.0, 0.5, curve: Curves.easeIn), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _animation2 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.5, 1.0, curve: Curves.easeOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _controller.repeat(); } diff --git a/lib/src/rotating_plain.dart b/lib/src/rotating_plain.dart index bed6705..ab7b6ea 100644 --- a/lib/src/rotating_plain.dart +++ b/lib/src/rotating_plain.dart @@ -1,12 +1,14 @@ import 'package:flutter/widgets.dart'; class SpinKitRotatingPlain extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitRotatingPlain({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -18,6 +20,7 @@ class SpinKitRotatingPlain extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitRotatingPlainState createState() => _SpinKitRotatingPlainState(); @@ -32,20 +35,21 @@ class _SpinKitRotatingPlainState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.0, 0.5, curve: Curves.easeIn), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _animation2 = Tween(begin: 0.0, end: 180.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.5, 1.0, curve: Curves.easeOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _controller.repeat(); } diff --git a/lib/src/spinning_circle.dart b/lib/src/spinning_circle.dart index 91b45fe..1a83035 100644 --- a/lib/src/spinning_circle.dart +++ b/lib/src/spinning_circle.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:flutter/widgets.dart'; class SpinKitSpinningCircle extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitSpinningCircle({ Key key, this.color, @@ -10,6 +11,7 @@ class SpinKitSpinningCircle extends StatefulWidget { this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -23,6 +25,7 @@ class SpinKitSpinningCircle extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitSpinningCircleState createState() => _SpinKitSpinningCircleState(); @@ -36,13 +39,14 @@ class _SpinKitSpinningCircleState extends State @override void initState() { super.initState(); - _controller = AnimationController(vsync: this, duration: widget.duration); + _controller = widget.controller ?? + AnimationController(vsync: this, duration: widget.duration); _animation1 = Tween(begin: 0.0, end: 7.0).animate( CurvedAnimation( parent: _controller, curve: const Interval(0.0, 1.0, curve: Curves.easeOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _controller.repeat(); } diff --git a/lib/src/three_bounce.dart b/lib/src/three_bounce.dart index f918a66..2a06566 100644 --- a/lib/src/three_bounce.dart +++ b/lib/src/three_bounce.dart @@ -2,12 +2,14 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_spinkit/src/utils.dart'; class SpinKitThreeBounce extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitThreeBounce({ Key key, this.color, this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1400), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -19,6 +21,7 @@ class SpinKitThreeBounce extends StatefulWidget { final double size; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitThreeBounceState createState() => _SpinKitThreeBounceState(); @@ -31,7 +34,8 @@ class _SpinKitThreeBounceState extends State @override void initState() { super.initState(); - _scaleCtrl = AnimationController(vsync: this, duration: widget.duration) + _scaleCtrl = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); } diff --git a/lib/src/wandering_cubes.dart b/lib/src/wandering_cubes.dart index 3cc6088..9e3f7ac 100644 --- a/lib/src/wandering_cubes.dart +++ b/lib/src/wandering_cubes.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; class SpinKitWanderingCubes extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitWanderingCubes({ Key key, this.color, @@ -42,28 +43,28 @@ class _SpinKitWanderingCubesState extends State parent: _translateCtrl, curve: const Interval(0.0, 0.25, curve: Curves.easeInOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _translate2 = Tween(begin: 0.0, end: _offset).animate( CurvedAnimation( parent: _translateCtrl, curve: const Interval(0.25, 0.5, curve: Curves.easeInOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _translate3 = Tween(begin: 0.0, end: -_offset).animate( CurvedAnimation( parent: _translateCtrl, curve: const Interval(0.5, 0.75, curve: Curves.easeInOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _translate4 = Tween(begin: 0.0, end: -_offset).animate( CurvedAnimation( parent: _translateCtrl, curve: const Interval(0.75, 1.0, curve: Curves.easeInOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _translateCtrl.repeat(); } @@ -76,28 +77,28 @@ class _SpinKitWanderingCubesState extends State parent: _scaleCtrl, curve: const Interval(0.0, 0.25, curve: Curves.easeInOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _scale2 = Tween(begin: 1.0, end: 2.0).animate( CurvedAnimation( parent: _scaleCtrl, curve: const Interval(0.25, 0.5, curve: Curves.easeInOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _scale3 = Tween(begin: 1.0, end: 0.5).animate( CurvedAnimation( parent: _scaleCtrl, curve: const Interval(0.5, 0.75, curve: Curves.easeInOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _scale4 = Tween(begin: 1.0, end: 2.0).animate( CurvedAnimation( parent: _scaleCtrl, curve: const Interval(0.75, 1.0, curve: Curves.easeInOut), ), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _scaleCtrl.repeat(); } @@ -114,7 +115,7 @@ class _SpinKitWanderingCubesState extends State _rotate = Tween(begin: 0.0, end: 360.0).animate( CurvedAnimation(parent: _translateCtrl, curve: Curves.linear), - )..addListener(() => setState(() => {})); + )..addListener(() => setState(() {})); _rotateCtrl.repeat(); } diff --git a/lib/src/wave.dart b/lib/src/wave.dart index 764145a..6b9a44f 100644 --- a/lib/src/wave.dart +++ b/lib/src/wave.dart @@ -4,6 +4,7 @@ import 'package:flutter_spinkit/src/utils.dart'; enum SpinKitWaveType { start, end, center } class SpinKitWave extends StatefulWidget { + // ignore: prefer_const_constructors_in_immutables SpinKitWave({ Key key, this.color, @@ -11,6 +12,7 @@ class SpinKitWave extends StatefulWidget { this.size = 50.0, this.itemBuilder, this.duration = const Duration(milliseconds: 1200), + this.controller, }) : assert( !(itemBuilder is IndexedWidgetBuilder && color is Color) && !(itemBuilder == null && color == null), @@ -24,6 +26,7 @@ class SpinKitWave extends StatefulWidget { final SpinKitWaveType type; final IndexedWidgetBuilder itemBuilder; final Duration duration; + final AnimationController controller; @override _SpinKitWaveState createState() => _SpinKitWaveState(); @@ -36,7 +39,8 @@ class _SpinKitWaveState extends State @override void initState() { super.initState(); - _scaleCtrl = AnimationController(vsync: this, duration: widget.duration) + _scaleCtrl = (widget.controller ?? + AnimationController(vsync: this, duration: widget.duration)) ..repeat(); } diff --git a/pubspec.lock b/pubspec.lock index 21d16f3..90f1b9b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.2.0" boolean_selector: dependency: transitive description: @@ -45,7 +45,7 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.5" meta: dependency: transitive description: @@ -60,13 +60,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.2" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.3" sky_engine: dependency: transitive description: flutter @@ -78,7 +85,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.5.5" stack_trace: dependency: transitive description: @@ -92,7 +99,7 @@ packages: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.0.0" string_scanner: dependency: transitive description: @@ -106,14 +113,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "0.2.5" typed_data: dependency: transitive description: @@ -129,5 +136,5 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.0.0 <3.0.0" + dart: ">=2.2.2 <3.0.0" flutter: ">=0.1.4 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 2e93cd2..8f467a2 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.1.0 +version: 4.0.0 homepage: https://github.com/jogboms/flutter_spinkit authors: @@ -8,7 +8,7 @@ authors: - Ayush Agarwal environment: - sdk: ">=2.0.0-dev.28.0 <3.0.0" + sdk: ">=2.1.0 <3.0.0" flutter: ">=0.1.4 <2.0.0" dependencies: