Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/button_stagger_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,19 @@ class ButtonStaggerAnimation extends StatelessWidget {
width: widthAnimation.value,
child: ElevatedButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
minimumSize: MaterialStateProperty.all(Size(30, 30)),
elevation: MaterialStateProperty.all(elevation),
shape: MaterialStateProperty.all(RoundedRectangleBorder(
borderRadius: borderRadiusAnimation.value,
side: BorderSide(
side: borderWidth!=null ?
BorderSide(
color: borderColor ?? Color(0xffff5745),
width: borderWidth!),
width: borderWidth!)
: BorderSide.none,
)),
foregroundColor: MaterialStateProperty.all(color),
backgroundColor: MaterialStateProperty.all(color),

),
child: _buttonChild(),
onPressed: () {
Expand All @@ -102,4 +107,4 @@ class ButtonStaggerAnimation extends StatelessWidget {
},
);
}
}
}
47 changes: 44 additions & 3 deletions lib/spinner_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@ import 'package:flutter/material.dart';

import 'button_stagger_animation.dart';

class SpinnerButtonController{

final AnimationController animationController;

SpinnerButtonController(this.animationController);

bool _isInProgress=false;
bool isDisposed=false;

bool get isInProgress{
return _isInProgress;
}

void set isInProgress(bool isInProgress) {
_isInProgress=isInProgress;

if(isDisposed){
return;
}

if(isInProgress){
animationController.forward();
}else{
animationController.reverse(from: animationController.value);
}

}

void dispose(){
isDisposed=true;
animationController.dispose();
}

}

class SpinnerButton extends StatefulWidget {
/// The background color of the button.
final Color color;
Expand Down Expand Up @@ -33,7 +68,7 @@ class SpinnerButton extends StatefulWidget {
///
/// This will grant access to its [AnimationController] so
/// that the animation can be controlled based on the need.
final Function(AnimationController? controller) onPressed;
final Function(SpinnerButtonController controller) onPressed;

/// The child to display on the button.
final Widget child;
Expand Down Expand Up @@ -62,6 +97,7 @@ class SpinnerButton extends StatefulWidget {
class _SpinnerButtonState extends State<SpinnerButton>
with TickerProviderStateMixin {
late AnimationController _controller;
late SpinnerButtonController spinnerButtonController;

@override
void initState() {
Expand All @@ -71,11 +107,12 @@ class _SpinnerButtonState extends State<SpinnerButton>
duration: widget.animationDuration,
vsync: this,
);
spinnerButtonController=SpinnerButtonController(_controller);
}

@override
void dispose() {
_controller.dispose();
spinnerButtonController.dispose();
super.dispose();
}

Expand All @@ -91,7 +128,11 @@ class _SpinnerButtonState extends State<SpinnerButton>
progressIndicatorColor: widget.progressIndicatorColor,
progressIndicatorSize: widget.progressIndicatorSize,
borderRadius: widget.borderRadius,
onPressed: widget.onPressed,
onPressed: (controller){
if(!spinnerButtonController.isInProgress){
widget.onPressed(spinnerButtonController);
}
},
elevation: widget.elevation,
child: widget.child,
),
Expand Down