Skip to content
Closed
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
58 changes: 45 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
# Don’t commit the following directories created by pub.
.buildlog
.pub/
build/
packages
.packages
.vscode/
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Or the files created by dart2js.
*.dart.js
*.js_
*.js.deps
*.js.map
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Include when developing application packages.
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/
pubspec.lock

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

ios/build
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ build/
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
/ios/Flutter/flutter_export_environment.sh
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
Expand Down
4 changes: 2 additions & 2 deletions example/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class App extends StatelessWidget {
fontSize: 24,
),
),
onPressed: (AnimationController controller) {
if (controller.isCompleted) {
onPressed: (AnimationController? controller) {
if (controller!.isCompleted) {
controller.reverse();
} else {
controller.forward();
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: An example for the progress button implementation.
version: 1.0.0+1

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand Down
36 changes: 18 additions & 18 deletions lib/button_stagger_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import 'package:flutter/material.dart';

class ButtonStaggerAnimation extends StatelessWidget {
// Animation fields
final AnimationController controller;
final AnimationController? controller;

// Display fields
final Color color;
final Color progressIndicatorColor;
final double progressIndicatorSize;
final BorderRadius borderRadius;
final double strokeWidth;
final Function(AnimationController) onPressed;
final Widget child;
final Color? color;
final Color? progressIndicatorColor;
final double? progressIndicatorSize;
final BorderRadius? borderRadius;
final double? strokeWidth;
final Function(AnimationController?)? onPressed;
final Widget? child;

ButtonStaggerAnimation({
Key key,
Key? key,
this.controller,
this.color,
this.progressIndicatorColor,
Expand All @@ -30,16 +30,16 @@ class ButtonStaggerAnimation extends StatelessWidget {
return LayoutBuilder(builder: _progressAnimatedBuilder);
}

Widget _buttonChild() {
if (controller.isAnimating) {
Widget? _buttonChild() {
if (controller!.isAnimating) {
return Container();
} else if (controller.isCompleted) {
} else if (controller!.isCompleted) {
return OverflowBox(
maxWidth: progressIndicatorSize,
maxHeight: progressIndicatorSize,
child: CircularProgressIndicator(
strokeWidth: strokeWidth,
valueColor: AlwaysStoppedAnimation<Color>(progressIndicatorColor),
strokeWidth: strokeWidth!,
valueColor: AlwaysStoppedAnimation<Color?>(progressIndicatorColor),
),
);
}
Expand All @@ -57,7 +57,7 @@ class ButtonStaggerAnimation extends StatelessWidget {
end: buttonHeight,
).animate(
CurvedAnimation(
parent: controller,
parent: controller!,
curve: Curves.easeInOut,
),
);
Expand All @@ -66,12 +66,12 @@ class ButtonStaggerAnimation extends StatelessWidget {
begin: borderRadius,
end: BorderRadius.all(Radius.circular(buttonHeight / 2.0)),
).animate(CurvedAnimation(
parent: controller,
parent: controller!,
curve: Curves.easeInOut,
));

return AnimatedBuilder(
animation: controller,
animation: controller!,
builder: (context, child) {
return SizedBox(
height: buttonHeight,
Expand All @@ -83,7 +83,7 @@ class ButtonStaggerAnimation extends StatelessWidget {
color: color,
child: _buttonChild(),
onPressed: () {
this.onPressed(controller);
this.onPressed!(controller);
},
),
);
Expand Down
16 changes: 11 additions & 5 deletions lib/progress_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@ 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;
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,
Expand All @@ -42,7 +48,7 @@ class ProgressButton extends StatefulWidget {

class _ProgressButtonState extends State<ProgressButton>
with TickerProviderStateMixin {
AnimationController _controller;
late AnimationController _controller;

@override
void initState() {
Expand All @@ -64,7 +70,7 @@ class _ProgressButtonState extends State<ProgressButton>
Widget build(BuildContext context) {
return Center(
child: ButtonStaggerAnimation(
controller: _controller.view,
controller: _controller.view as AnimationController?,
color: widget.color,
strokeWidth: widget.strokeWidth,
progressIndicatorColor: widget.progressIndicatorColor,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ author: Pascal Brosinski<pascal@brosinski.eu>
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:
Expand Down
2 changes: 1 addition & 1 deletion test/progress_button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ void main() {
await tester.tap(find.byType(RaisedButton));

final widget = tester.widget<ButtonStaggerAnimation>(find.byType(ButtonStaggerAnimation));
expect(widget.controller.isAnimating, true);
expect(widget.controller!.isAnimating, true);
});
}