From bea7a1ecd6477ee06271884e07093a068069670d Mon Sep 17 00:00:00 2001 From: juliano0365 Date: Mon, 15 Feb 2021 20:45:19 -0400 Subject: [PATCH] Added null safety --- README.md | 16 +++++----- example/lib/main.dart | 11 ++++++- example/pubspec.lock | 38 ++++++++++++------------ lib/src/slider.dart | 69 +++++++++++++++++++------------------------ pubspec.lock | 38 ++++++++++++------------ 5 files changed, 87 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index 9d955b8..f4a3b40 100644 --- a/README.md +++ b/README.md @@ -101,20 +101,20 @@ There are several options that allow for more control: |--------------|-----------------|--------------| | `action` | null | (required) Define an action after slidding a button | | `child` | null | For more customizable button add your own widget | -| `vibrationFlag` | true | controls vibration on successful dismissed | -| `height` | 60 | Gives a height to a widget | -| `width` | 240 | Gives a width to a widget | +| `vibrationFlag` | false | controls vibration on successful dismissed | +| `height` | null ?? 70 | Gives a height to a widget | +| `width` | null ?? 250 | Gives a width to a widget | | `backgroundColor` | Color(0xffececec) | Gives a background color to a widget | | `baseColor` | Color(0xff4a4a4a) | Gives a shimmer base color to a widget | | `highlightedColor` | Colors.white | Gives a shimmer highlighted color to a widget | | `buttonColor` | Colors.black | Gives a color to a slidder button | -| `label` | Text("Slide to cancel !", style: TextStyle( fontSize: 17),) | A text widget which assigns a label. | +| `label` | null | A text widget which assigns a label. | | `alignLabel` | Alignment(0.4, 0) | Aligns text label | -| `boxShadow` | BoxShadow(color: Colors.black,blurRadius: 4,) | Gives a shadow to a slidder button | -| `icon` | Center( child: Icon( Icons.power_settings_new,color: Colors.white,size: 40.0,)) | A widget to provide an icon to a button | -| `shimmer` | true | enables/disables shimmer effect on the label | +| `boxShadow` | null | Gives a shadow to a slidder button | +| `icon` | null | A widget to provide an icon to a button | +| `shimmer` | false | enables/disables shimmer effect on the label | | `dismissible` | true | Make it false if you want maintain the widget in the tree | -| `buttonSize` | 60 | Gives size to a button | +| `buttonSize` | null ?? 60 | Gives size to a button | | `dismissThresholds` | 1.0 | The offset threshold when it should be considered dismissed |
diff --git a/example/lib/main.dart b/example/lib/main.dart index 72fc123..dd456c4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -20,7 +20,6 @@ class MainApp extends StatelessWidget { ///Do something here OnSlide print("working"); }, - ///Put label over here label: Text( "Slide to cancel !", @@ -37,6 +36,16 @@ class MainApp extends StatelessWidget { semanticLabel: 'Text to announce in accessibility modes', )), + //Put BoxShadow here + boxShadow: BoxShadow( + color: Colors.black, + blurRadius: 4, + ), + + //Adjust effects such as shimmer and flag vibration here + // shimmer: true, + // vibrationFlag: true, + ///Change All the color and size from here. width: 230, radius: 10, diff --git a/example/pubspec.lock b/example/pubspec.lock index 7353d34..4338ba7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,42 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.3" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.5" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.5" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +56,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -78,28 +78,28 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3-nullsafety.3" + version: "0.6.3" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.3" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.6" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.3" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -118,56 +118,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.4" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.6" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.6" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.5" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.5" + version: "2.1.0" vibration: dependency: transitive description: diff --git a/lib/src/slider.dart b/lib/src/slider.dart index ad90a09..b70f8ce 100644 --- a/lib/src/slider.dart +++ b/lib/src/slider.dart @@ -46,36 +46,25 @@ class SliderButton extends StatefulWidget { final bool disable; SliderButton({ @required this.action, - this.radius = 100, - this.boxShadow = const BoxShadow( - color: Colors.black, - blurRadius: 4, - ), + this.radius, + this.boxShadow, this.child, - this.vibrationFlag = true, - this.shimmer = true, - this.height = 70, - this.buttonSize = 60, - this.width = 250, + this.vibrationFlag, + this.shimmer, + this.height, + this.buttonSize, + this.width, this.alignLabel = const Alignment(0.4, 0), this.backgroundColor = const Color(0xffe0e0e0), this.baseColor = Colors.black87, this.buttonColor = Colors.white, this.highlightedColor = Colors.white, - this.label = const Text( - "Slide to cancel !", - style: TextStyle(fontWeight: FontWeight.w400, fontSize: 18), - ), - this.icon = const Icon( - Icons.power_settings_new, - color: Colors.red, - size: 30.0, - semanticLabel: 'Text to announce in accessibility modes', - ), + this.label, + this.icon, this.dismissible = true, this.dismissThresholds = 1.0, this.disable = false, - }) : assert(buttonSize <= height); + }) : assert((buttonSize ?? 60) <= (height ?? 70)); @override _SliderButtonState createState() => _SliderButtonState(); @@ -102,19 +91,19 @@ class _SliderButtonState extends State { } Widget _control() => Container( - height: widget.height, - width: widget.width, + height: widget.height ?? 70, + width: widget.width ?? 250, decoration: BoxDecoration( color: widget.disable ? Colors.grey.shade700 : widget.backgroundColor, - borderRadius: BorderRadius.circular(widget.radius)), + borderRadius: BorderRadius.circular(widget.radius ?? 100)), alignment: Alignment.centerLeft, child: Stack( alignment: Alignment.centerLeft, children: [ Container( alignment: widget.alignLabel, - child: widget.shimmer && !widget.disable + child: widget.shimmer ?? true && !widget.disable ? Shimmer.fromColors( baseColor: widget.disable ? Colors.grey : widget.baseColor, @@ -128,23 +117,25 @@ class _SliderButtonState extends State { verticalOffset: 50, message: 'Button is disabled', child: Container( - width: widget.width - (widget.height), - height: widget.height, + width: (widget.width ?? 250) - (widget.height ?? 70), + height: (widget.height - 70), alignment: Alignment.centerLeft, padding: EdgeInsets.only( - left: (widget.height - widget.buttonSize) / 2, + left: widget.height == null ? + (70 - (widget.buttonSize == null ? 60 : widget.buttonSize)) / 2 : + (widget.height - (widget.buttonSize == null ? widget.height * 0.9 : widget.buttonSize)) / 2, ), child: widget.child ?? Container( - height: widget.buttonSize, - width: widget.buttonSize, + height: widget.buttonSize ?? widget.height ?? 70 * 0.9, + width: widget.buttonSize ?? widget.height ?? 70 * 0.9, decoration: BoxDecoration( boxShadow: [ widget.boxShadow, ], color: Colors.grey, borderRadius: - BorderRadius.circular(widget.radius)), + BorderRadius.circular(widget.radius ?? 100)), child: Center(child: widget.icon), ), ), @@ -167,7 +158,7 @@ class _SliderButtonState extends State { }); widget.action(); - if (widget.vibrationFlag && + if (widget.vibrationFlag ?? true && await Vibration.hasVibrator()) { try { Vibration.vibrate(duration: 200); @@ -177,23 +168,25 @@ class _SliderButtonState extends State { } }, child: Container( - width: widget.width - (widget.height), - height: widget.height, + width: (widget.width ?? 250) - (widget.height ?? 70), + height: widget.height ?? 70, alignment: Alignment.centerLeft, padding: EdgeInsets.only( - left: (widget.height - widget.buttonSize) / 2, + left: widget.height == null ? + (70 - (widget.buttonSize == null ? 60 : widget.buttonSize)) / 2 : + (widget.height - (widget.buttonSize == null ? widget.height * 0.9 : widget.buttonSize)) / 2, ), child: widget.child ?? Container( - height: widget.buttonSize, - width: widget.buttonSize, + height: widget.buttonSize ?? widget.height ?? 70 * 0.9, + width: widget.buttonSize ?? widget.height ?? 70 * 0.9, decoration: BoxDecoration( boxShadow: [ widget.boxShadow, ], color: widget.buttonColor, borderRadius: - BorderRadius.circular(widget.radius)), + BorderRadius.circular(widget.radius ?? 100)), child: Center(child: widget.icon), ), ), diff --git a/pubspec.lock b/pubspec.lock index 0dac955..dc04a57 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.3" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.5" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.5" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -71,28 +71,28 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3-nullsafety.3" + version: "0.6.3" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.3" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.6" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.3" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -104,56 +104,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.4" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.6" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.6" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.5" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.5" + version: "2.1.0" vibration: dependency: "direct main" description: