diff --git a/lib/button_stagger_animation.dart b/lib/button_stagger_animation.dart index 57ba1a7..fcf6005 100644 --- a/lib/button_stagger_animation.dart +++ b/lib/button_stagger_animation.dart @@ -10,19 +10,23 @@ 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; 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,35 @@ 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 != null + ? () { + onPressed!(controller); + } + : null, + child: _buttonChild(), + ) + : ElevatedButton( + style: ElevatedButton.styleFrom( + primary: color, + shape: RoundedRectangleBorder( + borderRadius: borderRadiusAnimation.value, + ), + ), + onPressed: onPressed != null + ? () { + onPressed!(controller); + } + : null, + child: _buttonChild(), + ), ); }, ); diff --git a/lib/progress_button.dart b/lib/progress_button.dart index 7039236..a6683c7 100644 --- a/lib/progress_button.dart +++ b/lib/progress_button.dart @@ -6,34 +6,49 @@ import 'package:progress_indicator_button/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; + /// If it is null, the button will be disabled. + 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); }); }