From 6b3f8801b282f3eab0883cd5a868c05699231305 Mon Sep 17 00:00:00 2001 From: Mahdi Javaheri Saber Date: Thu, 3 Jun 2021 12:00:37 +0430 Subject: [PATCH] Add null safety support --- ...nter.dart => circle_progress_painter.dart} | 25 +-- ...essbar.dart => interval_progress_bar.dart} | 52 ++--- pubspec.lock | 188 ------------------ pubspec.yaml | 4 +- 4 files changed, 35 insertions(+), 234 deletions(-) rename lib/{CircleProgressPainter.dart => circle_progress_painter.dart} (74%) rename lib/{intervalprogressbar.dart => interval_progress_bar.dart} (86%) delete mode 100644 pubspec.lock diff --git a/lib/CircleProgressPainter.dart b/lib/circle_progress_painter.dart similarity index 74% rename from lib/CircleProgressPainter.dart rename to lib/circle_progress_painter.dart index 61fd22b..ad0f24a 100644 --- a/lib/CircleProgressPainter.dart +++ b/lib/circle_progress_painter.dart @@ -1,8 +1,7 @@ import 'dart:math'; import 'dart:ui'; - import 'package:flutter/material.dart'; -import 'package:intervalprogressbar/intervalprogressbar.dart'; +import 'package:zireh/widgets/interval_progress_bar/interval_progress_bar.dart'; class CircleProgressPainter extends IntervalProgressPainter { final double strokeWidth; @@ -19,22 +18,13 @@ class CircleProgressPainter extends IntervalProgressPainter { bool reverse, double intervalPercent, this.strokeWidth) - : super( - max, - progress, - intervalSize, - highlightColor, - defaultColor, - intervalColor, - intervalHighlightColor, - radius, - reverse, - intervalPercent); + : super(max, progress, intervalSize, highlightColor, defaultColor, intervalColor, + intervalHighlightColor, radius, reverse, intervalPercent); @override Size calBlockSize() { //Circle Progress will not call this - return null; + return Size(0, 0); } @override @@ -53,12 +43,11 @@ class CircleProgressPainter extends IntervalProgressPainter { Rect rect = Offset.zero & size; final radius = min(rect.height, rect.width); - final r = - Rect.fromCenter(center: rect.center, width: radius, height: radius); + final r = Rect.fromCenter(center: rect.center, width: radius, height: radius); - final incr = (360.0 - this.intervalDegrees * (this.max - 1)) / (this.max); + final degrees = (360.0 - this.intervalDegrees * (this.max - 1)) / (this.max); final intervalRadians = degrees2radians(this.intervalDegrees); - final swap = degrees2radians(incr); + final swap = degrees2radians(degrees); var start = 0.0; diff --git a/lib/intervalprogressbar.dart b/lib/interval_progress_bar.dart similarity index 86% rename from lib/intervalprogressbar.dart rename to lib/interval_progress_bar.dart index e9b7947..5cbd33d 100644 --- a/lib/intervalprogressbar.dart +++ b/lib/interval_progress_bar.dart @@ -3,7 +3,7 @@ library intervalprogressbar; import 'dart:ui'; import 'package:flutter/widgets.dart'; -import 'package:intervalprogressbar/CircleProgressPainter.dart'; +import 'package:zireh/widgets/interval_progress_bar/circle_progress_painter.dart'; class IntervalProgressBar extends StatelessWidget { final IntervalProgressDirection direction; @@ -21,20 +21,20 @@ class IntervalProgressBar extends StatelessWidget { final double strokeWith; const IntervalProgressBar( - {Key key, - this.direction = IntervalProgressDirection.horizontal, - @required this.max, - @required this.progress, - @required this.intervalSize, - @required this.size, - @required this.highlightColor, - @required this.defaultColor, - @required this.intervalColor, - @required this.intervalHighlightColor, - @required this.radius, - this.reverse = false, - this.intervalDegrees = 0.0, - this.strokeWith = 0}) + {Key? key, + this.direction = IntervalProgressDirection.horizontal, + required this.max, + required this.progress, + required this.intervalSize, + required this.size, + required this.highlightColor, + required this.defaultColor, + required this.intervalColor, + required this.intervalHighlightColor, + required this.radius, + this.reverse = false, + this.intervalDegrees = 0.0, + this.strokeWith = 0}) : super(key: key); static const IntervalProgressBar demo = IntervalProgressBar( @@ -117,7 +117,7 @@ abstract class IntervalProgressPainter extends CustomPainter { ..style = PaintingStyle.fill ..isAntiAlias = true; - Rect bound; + Rect bound = Rect.zero; IntervalProgressPainter( this.max, @@ -173,8 +173,8 @@ abstract class IntervalProgressPainter extends CustomPainter { bool shouldDrawInterval(int index) => index != this.max - 1 && - (intervalColor != IntervalProgressBar.TRANSPARENT || - intervalHighlightColor != IntervalProgressBar.TRANSPARENT); + (intervalColor != IntervalProgressBar.TRANSPARENT || + intervalHighlightColor != IntervalProgressBar.TRANSPARENT); } class HorizontalProgressPainter extends IntervalProgressPainter { @@ -189,7 +189,7 @@ class HorizontalProgressPainter extends IntervalProgressPainter { double radius, bool reverse) : super(max, progress, intervalSize, highlightColor, defaultColor, - intervalColor, intervalHighlightColor, radius, reverse, 0.0); + intervalColor, intervalHighlightColor, radius, reverse, 0.0); @override Size calBlockSize() => Size( @@ -217,7 +217,7 @@ class HorizontalProgressPainter extends IntervalProgressPainter { if (shouldDrawInterval(i)) { painter.color = - highlightInterval(i) ? intervalHighlightColor : intervalColor; + highlightInterval(i) ? intervalHighlightColor : intervalColor; canvas.drawRect( Rect.fromLTRB( blockWidth, @@ -232,14 +232,14 @@ class HorizontalProgressPainter extends IntervalProgressPainter { Rect _drawLeftRound(Canvas canvas, Rect rect) { final clipRect = - Rect.fromLTRB(rect.left + radius, rect.top, rect.right, rect.bottom); + Rect.fromLTRB(rect.left + radius, rect.top, rect.right, rect.bottom); _drawRadius(canvas, rect, clipRect); return clipRect; } Rect _drawRightRound(Canvas canvas, Rect rect) { final clipRect = - Rect.fromLTRB(rect.left, rect.top, rect.right - radius, rect.bottom); + Rect.fromLTRB(rect.left, rect.top, rect.right - radius, rect.bottom); _drawRadius(canvas, rect, clipRect); return clipRect; } @@ -267,7 +267,7 @@ class VerticalProgressPainter extends IntervalProgressPainter { double radius, bool reverse) : super(max, progress, intervalSize, highlightColor, defaultColor, - intervalColor, intervalHighlightColor, radius, reverse, 0.0); + intervalColor, intervalHighlightColor, radius, reverse, 0.0); @override void paintBlock(Canvas canvas, int i, Size blockSize) { @@ -287,7 +287,7 @@ class VerticalProgressPainter extends IntervalProgressPainter { canvas.drawRect(rect, painter); if (shouldDrawInterval(i)) { painter.color = - highlightInterval(i) ? intervalHighlightColor : intervalColor; + highlightInterval(i) ? intervalHighlightColor : intervalColor; final intervalRect = Rect.fromLTRB( 0, blockHeight, bound.width, blockHeight + intervalSize); canvas.drawRect(intervalRect, painter); @@ -301,14 +301,14 @@ class VerticalProgressPainter extends IntervalProgressPainter { Rect _drawStartRadius(Canvas canvas, Rect rect) { final clipRect = - Rect.fromLTRB(rect.left, rect.top + radius, rect.right, rect.bottom); + Rect.fromLTRB(rect.left, rect.top + radius, rect.right, rect.bottom); _drawRadius(canvas, rect, clipRect); return clipRect; } Rect _drawEndRadius(Canvas canvas, Rect rect) { final clipRect = - Rect.fromLTRB(rect.left, rect.top, rect.right, rect.bottom - radius); + Rect.fromLTRB(rect.left, rect.top, rect.right, rect.bottom - radius); _drawRadius(canvas, rect, clipRect); return clipRect; } diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index 25510ed..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,188 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.5.2" - async: - dependency: transitive - description: - name: async - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.4.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.0.5" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.1.2" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.14.11" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.1" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.3" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.4" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.12.6" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.1.8" - path: - dependency: transitive - description: - name: path - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.6.4" - pedantic: - dependency: "direct main" - description: - name: pedantic - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.5" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.5.5" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.9.3" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.0.5" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.1.0" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.2.11" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.1.6" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.flutter-io.cn" - source: hosted - version: "3.5.0" -sdks: - dart: ">=2.4.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index bb14154..f5d6b3b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: intervalprogressbar description: A interval progress bar for Flutter. Horizontal, vertical, colorful and interval progress. -version: 2.0.1 +version: 2.1.0 homepage: https://github.com/stefanJi/IntervalProgressBar environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.13.0 <3.0.0" dependencies: flutter: