From 8c2ce711fd0b5b947265fd1339dcf21eabcbcd5d Mon Sep 17 00:00:00 2001 From: Bhupesh-V Date: Wed, 16 Feb 2022 21:34:31 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20migrate=20to=20null-safety?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 58 ++++++++++++++++++++++++------- example/.gitignore | 1 + example/android/app/build.gradle | 2 +- example/lib/src/app.dart | 4 +-- example/pubspec.yaml | 2 +- lib/button_stagger_animation.dart | 36 +++++++++---------- lib/progress_button.dart | 16 ++++++--- pubspec.yaml | 2 +- test/progress_button_test.dart | 2 +- 9 files changed, 81 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 767b5d9..3482b48 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/example/.gitignore b/example/.gitignore index 47e0b4d..021cd48 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -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 diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index a9339df..f987638 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -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' diff --git a/example/lib/src/app.dart b/example/lib/src/app.dart index c3ed6a2..544a0f6 100644 --- a/example/lib/src/app.dart +++ b/example/lib/src/app.dart @@ -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(); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 4633ee3..514745b 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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: diff --git a/lib/button_stagger_animation.dart b/lib/button_stagger_animation.dart index 57ba1a7..f46f16b 100644 --- a/lib/button_stagger_animation.dart +++ b/lib/button_stagger_animation.dart @@ -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, @@ -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(progressIndicatorColor), + strokeWidth: strokeWidth!, + valueColor: AlwaysStoppedAnimation(progressIndicatorColor), ), ); } @@ -57,7 +57,7 @@ class ButtonStaggerAnimation extends StatelessWidget { end: buttonHeight, ).animate( CurvedAnimation( - parent: controller, + parent: controller!, curve: Curves.easeInOut, ), ); @@ -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, @@ -83,7 +83,7 @@ class ButtonStaggerAnimation extends StatelessWidget { color: color, child: _buttonChild(), onPressed: () { - this.onPressed(controller); + this.onPressed!(controller); }, ), ); diff --git a/lib/progress_button.dart b/lib/progress_button.dart index 7039236..243fc00 100644 --- a/lib/progress_button.dart +++ b/lib/progress_button.dart @@ -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, @@ -42,7 +48,7 @@ class ProgressButton extends StatefulWidget { class _ProgressButtonState extends State with TickerProviderStateMixin { - AnimationController _controller; + late AnimationController _controller; @override void initState() { @@ -64,7 +70,7 @@ class _ProgressButtonState extends State 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, diff --git a/pubspec.yaml b/pubspec.yaml index cbc0389..5f31762 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ 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..e69b5ec 100644 --- a/test/progress_button_test.dart +++ b/test/progress_button_test.dart @@ -13,6 +13,6 @@ void main() { await tester.tap(find.byType(RaisedButton)); final widget = tester.widget(find.byType(ButtonStaggerAnimation)); - expect(widget.controller.isAnimating, true); + expect(widget.controller!.isAnimating, true); }); }