From 268a47a499c70b49c451246be64f110bdc6fee0a Mon Sep 17 00:00:00 2001 From: Amrit Kahlon Date: Thu, 15 Apr 2021 19:14:17 -0700 Subject: [PATCH 1/4] Migrated to null safety and added outlined button support --- lib/button_stagger_animation.dart | 59 ++++++++++++++++++++----------- lib/progress_button.dart | 29 +++++++++++---- pubspec.yaml | 4 +-- test/progress_button_test.dart | 8 +++-- 4 files changed, 69 insertions(+), 31 deletions(-) diff --git a/lib/button_stagger_animation.dart b/lib/button_stagger_animation.dart index 57ba1a7..92db87c 100644 --- a/lib/button_stagger_animation.dart +++ b/lib/button_stagger_animation.dart @@ -12,17 +12,21 @@ class ButtonStaggerAnimation extends StatelessWidget { final double strokeWidth; final Function(AnimationController) onPressed; final Widget child; + final bool outlined; + final double height; ButtonStaggerAnimation({ - Key key, - this.controller, - this.color, - this.progressIndicatorColor, - this.progressIndicatorSize, - this.borderRadius, - this.onPressed, - this.strokeWidth, - this.child, + Key? key, + required this.controller, + required this.color, + required this.progressIndicatorColor, + required this.progressIndicatorSize, + required this.borderRadius, + required this.onPressed, + required this.strokeWidth, + required this.child, + required this.outlined, + required this.height, }) : super(key: key); @override @@ -50,7 +54,7 @@ class ButtonStaggerAnimation extends StatelessWidget { BuildContext context, BoxConstraints constraints) { var buttonHeight = (constraints.maxHeight != double.infinity) ? constraints.maxHeight - : 60.0; + : height; var widthAnimation = Tween( begin: constraints.maxWidth, @@ -76,16 +80,31 @@ class ButtonStaggerAnimation extends StatelessWidget { return SizedBox( height: buttonHeight, width: widthAnimation.value, - child: RaisedButton( - shape: RoundedRectangleBorder( - borderRadius: borderRadiusAnimation.value, - ), - color: color, - child: _buttonChild(), - onPressed: () { - this.onPressed(controller); - }, - ), + child: outlined + ? OutlinedButton( + style: OutlinedButton.styleFrom( + primary: color, + shape: RoundedRectangleBorder( + borderRadius: borderRadiusAnimation.value, + ), + ), + onPressed: () { + onPressed(controller); + }, + child: _buttonChild(), + ) + : ElevatedButton( + style: ElevatedButton.styleFrom( + primary: color, + shape: RoundedRectangleBorder( + borderRadius: borderRadiusAnimation.value, + ), + ), + onPressed: () { + onPressed(controller); + }, + child: _buttonChild(), + ), ); }, ); diff --git a/lib/progress_button.dart b/lib/progress_button.dart index 7039236..83025b7 100644 --- a/lib/progress_button.dart +++ b/lib/progress_button.dart @@ -1,39 +1,54 @@ library progress_button; import 'package:flutter/material.dart'; -import 'package:progress_indicator_button/button_stagger_animation.dart'; + +import './button_stagger_animation.dart'; class ProgressButton extends StatefulWidget { /// The background color of the button. final Color color; + /// The progress indicator color. final Color progressIndicatorColor; + /// The size of the progress indicator. final double progressIndicatorSize; + /// The border radius while NOT animating. final BorderRadius borderRadius; + /// The duration of the animation. final Duration animationDuration; /// The stroke width of progress indicator. final double strokeWidth; + + /// Changes to an outlined button. + final bool outlined; + + /// The height of the button unless it is constrained. + final double height; + /// Function that will be called at the on pressed event. /// /// This will grant access to its [AnimationController] so /// that the animation can be controlled based on the need. final Function(AnimationController) onPressed; + /// The child to display on the button. final Widget child; ProgressButton({ - @required this.child, - @required this.onPressed, + required this.child, + required this.onPressed, this.color = Colors.blue, this.strokeWidth = 2, this.progressIndicatorColor = Colors.white, this.progressIndicatorSize = 30, this.borderRadius = const BorderRadius.all(Radius.circular(0)), this.animationDuration = const Duration(milliseconds: 300), + this.outlined = false, + this.height = 60.0, }); @override @@ -42,7 +57,7 @@ class ProgressButton extends StatefulWidget { class _ProgressButtonState extends State with TickerProviderStateMixin { - AnimationController _controller; + AnimationController? _controller; @override void initState() { @@ -56,7 +71,7 @@ class _ProgressButtonState extends State @override void dispose() { - _controller.dispose(); + _controller?.dispose(); super.dispose(); } @@ -64,13 +79,15 @@ class _ProgressButtonState extends State Widget build(BuildContext context) { return Center( child: ButtonStaggerAnimation( - controller: _controller.view, + controller: _controller!, color: widget.color, strokeWidth: widget.strokeWidth, progressIndicatorColor: widget.progressIndicatorColor, progressIndicatorSize: widget.progressIndicatorSize, borderRadius: widget.borderRadius, onPressed: widget.onPressed, + outlined: widget.outlined, + height: widget.height, child: widget.child, ), ); diff --git a/pubspec.yaml b/pubspec.yaml index cbc0389..367508d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: progress_indicator_button description: A simple button which can transform and show a progress indicator. -version: 0.0.3 +version: 0.0.4 author: Pascal Brosinski homepage: https://github.com/PascalAC/progress_button environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: diff --git a/test/progress_button_test.dart b/test/progress_button_test.dart index 036913f..f60eba4 100644 --- a/test/progress_button_test.dart +++ b/test/progress_button_test.dart @@ -5,14 +5,16 @@ import 'package:progress_indicator_button/progress_button.dart'; import '../example/lib/src/app.dart'; void main() { - testWidgets('ProgressButton - Start animation on click', (WidgetTester tester) async { + testWidgets('ProgressButton - Start animation on click', + (WidgetTester tester) async { await tester.pumpWidget(App()); expect(find.byType(ProgressButton), findsOneWidget); - await tester.tap(find.byType(RaisedButton)); + await tester.tap(find.byType(ElevatedButton)); - final widget = tester.widget(find.byType(ButtonStaggerAnimation)); + final widget = tester + .widget(find.byType(ButtonStaggerAnimation)); expect(widget.controller.isAnimating, true); }); } From 76d7fe250bcf095a6e226b9869f0d1a66ac9de0f Mon Sep 17 00:00:00 2001 From: Amrit Kahlon Date: Thu, 15 Apr 2021 19:15:43 -0700 Subject: [PATCH 2/4] Added back in import --- lib/progress_button.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/progress_button.dart b/lib/progress_button.dart index 83025b7..4a5cf9e 100644 --- a/lib/progress_button.dart +++ b/lib/progress_button.dart @@ -2,7 +2,7 @@ library progress_button; import 'package:flutter/material.dart'; -import './button_stagger_animation.dart'; +import 'package:progress_indicator_button/button_stagger_animation.dart'; class ProgressButton extends StatefulWidget { /// The background color of the button. From 26c4e5b498755f596c2991a9a2052be80d5eef00 Mon Sep 17 00:00:00 2001 From: Amrit Kahlon Date: Thu, 15 Apr 2021 19:16:12 -0700 Subject: [PATCH 3/4] Removed spacing from import --- lib/progress_button.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/progress_button.dart b/lib/progress_button.dart index 4a5cf9e..4f9c72d 100644 --- a/lib/progress_button.dart +++ b/lib/progress_button.dart @@ -1,7 +1,6 @@ library progress_button; import 'package:flutter/material.dart'; - import 'package:progress_indicator_button/button_stagger_animation.dart'; class ProgressButton extends StatefulWidget { From 0cc6b2d8eb5898cd75ea9c75fb01fc985c74e0e9 Mon Sep 17 00:00:00 2001 From: Amrit Kahlon Date: Wed, 5 May 2021 17:47:56 -0700 Subject: [PATCH 4/4] Allow function to be null to disable button --- lib/button_stagger_animation.dart | 18 +++++++++++------- lib/progress_button.dart | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/button_stagger_animation.dart b/lib/button_stagger_animation.dart index 92db87c..fcf6005 100644 --- a/lib/button_stagger_animation.dart +++ b/lib/button_stagger_animation.dart @@ -10,7 +10,7 @@ class ButtonStaggerAnimation extends StatelessWidget { final double progressIndicatorSize; final BorderRadius borderRadius; final double strokeWidth; - final Function(AnimationController) onPressed; + final Function(AnimationController)? onPressed; final Widget child; final bool outlined; final double height; @@ -88,9 +88,11 @@ class ButtonStaggerAnimation extends StatelessWidget { borderRadius: borderRadiusAnimation.value, ), ), - onPressed: () { - onPressed(controller); - }, + onPressed: onPressed != null + ? () { + onPressed!(controller); + } + : null, child: _buttonChild(), ) : ElevatedButton( @@ -100,9 +102,11 @@ class ButtonStaggerAnimation extends StatelessWidget { borderRadius: borderRadiusAnimation.value, ), ), - onPressed: () { - onPressed(controller); - }, + onPressed: onPressed != null + ? () { + onPressed!(controller); + } + : null, child: _buttonChild(), ), ); diff --git a/lib/progress_button.dart b/lib/progress_button.dart index 4f9c72d..a6683c7 100644 --- a/lib/progress_button.dart +++ b/lib/progress_button.dart @@ -32,7 +32,8 @@ class ProgressButton extends StatefulWidget { /// /// This will grant access to its [AnimationController] so /// that the animation can be controlled based on the need. - final Function(AnimationController) onPressed; + /// If it is null, the button will be disabled. + final Function(AnimationController)? onPressed; /// The child to display on the button. final Widget child;