forked from PascalAC/progress_button
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress_button.dart
78 lines (68 loc) · 2.17 KB
/
progress_button.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
library progress_button;
import 'package:flutter/material.dart';
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;
/// 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,
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),
});
@override
_ProgressButtonState createState() => _ProgressButtonState();
}
class _ProgressButtonState extends State<ProgressButton>
with TickerProviderStateMixin {
AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: widget.animationDuration,
vsync: this,
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
child: ButtonStaggerAnimation(
controller: _controller.view,
color: widget.color,
strokeWidth: widget.strokeWidth,
progressIndicatorColor: widget.progressIndicatorColor,
progressIndicatorSize: widget.progressIndicatorSize,
borderRadius: widget.borderRadius,
onPressed: widget.onPressed,
child: widget.child,
),
);
}
}