Skip to content

Commit

Permalink
Added additional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisedg87 committed Sep 18, 2021
1 parent 1c26cc0 commit 066cbb1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.0.8]
* Added success and error icons parameters
* Added completion curve and duration parameters

## [2.0.7]
* Updated rxdart constraints
* Updated the screenshot
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RoundedLoadingButton is a Flutter package with a simple implementation of an ani
Add this to your pubspec.yaml:

dependencies:
rounded_loading_button: ^2.0.6
rounded_loading_button: ^2.0.8

## Usage

Expand Down Expand Up @@ -48,6 +48,8 @@ The Rounded Loading Button has many configurable properties, including:
* `resetAfterDuration` - Reset the animation after specified duration, defaults to 15 seconds
* `errorColor` - The color of the button when it is in the error state
* `successColor` - The color of the button when it is in the success state
* `successIcon` - The icon for the success state
* `failedIcon` - The icon for the failed state


## Contributions
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class _MyHomePageState extends State<MyHomePage> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RoundedLoadingButton(
successIcon: Icons.cloud,
failedIcon: Icons.cottage,
child: Text('Tap me!', style: TextStyle(color: Colors.white)),
controller: _btnController1,
onPressed: () => _doSomething(_btnController1),
Expand Down
25 changes: 21 additions & 4 deletions lib/rounded_loading_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ class RoundedLoadingButton extends StatefulWidget {
/// The color of the button when it is disabled
final Color? disabledColor;

/// The icon for the success state
final IconData successIcon;

/// The icon for the failed state
final IconData failedIcon;

/// The success and failed animation curve
final Curve completionCurve;

/// The duration of the success and failed animation
final Duration completionDuration;

Duration get _borderDuration {
return Duration(milliseconds: (duration.inMilliseconds / 2).round());
}
Expand All @@ -93,6 +105,10 @@ class RoundedLoadingButton extends StatefulWidget {
this.successColor,
this.resetDuration = const Duration(seconds: 15),
this.resetAfterDuration = false,
this.successIcon = Icons.check,
this.failedIcon = Icons.close,
this.completionCurve = Curves.elasticOut,
this.completionDuration = const Duration(milliseconds: 1000),
this.disabledColor}) : super(key: key);

@override
Expand Down Expand Up @@ -127,7 +143,7 @@ class RoundedLoadingButtonState extends State<RoundedLoadingButton>
height: _bounceAnimation.value,
child: _bounceAnimation.value > 20
? Icon(
Icons.check,
widget.successIcon,
color: widget.valueColor,
)
: null);
Expand All @@ -143,7 +159,7 @@ class RoundedLoadingButtonState extends State<RoundedLoadingButton>
height: _bounceAnimation.value,
child: _bounceAnimation.value > 20
? Icon(
Icons.close,
widget.failedIcon,
color: widget.valueColor,
)
: null);
Expand All @@ -168,6 +184,7 @@ class RoundedLoadingButtonState extends State<RoundedLoadingButton>
final _btn = ButtonTheme(
shape: RoundedRectangleBorder(borderRadius: _borderAnimation.value),
disabledColor: widget.disabledColor,
padding: EdgeInsets.all(0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
onSurface: widget.disabledColor,
Expand Down Expand Up @@ -201,14 +218,14 @@ class RoundedLoadingButtonState extends State<RoundedLoadingButton>
AnimationController(duration: widget.duration, vsync: this);

_checkButtonControler = AnimationController(
duration: Duration(milliseconds: 1000), vsync: this);
duration: widget.completionDuration, vsync: this);

_borderController =
AnimationController(duration: widget._borderDuration, vsync: this);

_bounceAnimation = Tween<double>(begin: 0, end: widget.height).animate(
CurvedAnimation(
parent: _checkButtonControler, curve: Curves.elasticOut));
parent: _checkButtonControler, curve: widget.completionCurve));
_bounceAnimation.addListener(() {
setState(() {});
});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: rounded_loading_button
description: A simple implementation of an animated loading button widget for Flutter
version: 2.0.7
version: 2.0.8
homepage: https://github.com/chrisedg87/flutter_rounded_loading_button

environment:
Expand Down

0 comments on commit 066cbb1

Please sign in to comment.