Skip to content

Commit

Permalink
Added null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
julianodportela committed Feb 16, 2021
1 parent 23fa60b commit bea7a1e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 85 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

<br>
Expand Down
11 changes: 10 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class MainApp extends StatelessWidget {
///Do something here OnSlide
print("working");
},

///Put label over here
label: Text(
"Slide to cancel !",
Expand All @@ -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,
Expand Down
38 changes: 19 additions & 19 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
69 changes: 31 additions & 38 deletions lib/src/slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -102,19 +91,19 @@ class _SliderButtonState extends State<SliderButton> {
}

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: <Widget>[
Container(
alignment: widget.alignLabel,
child: widget.shimmer && !widget.disable
child: widget.shimmer ?? true && !widget.disable
? Shimmer.fromColors(
baseColor:
widget.disable ? Colors.grey : widget.baseColor,
Expand All @@ -128,23 +117,25 @@ class _SliderButtonState extends State<SliderButton> {
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),
),
),
Expand All @@ -167,7 +158,7 @@ class _SliderButtonState extends State<SliderButton> {
});

widget.action();
if (widget.vibrationFlag &&
if (widget.vibrationFlag ?? true &&
await Vibration.hasVibrator()) {
try {
Vibration.vibrate(duration: 200);
Expand All @@ -177,23 +168,25 @@ class _SliderButtonState extends State<SliderButton> {
}
},
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),
),
),
Expand Down
Loading

0 comments on commit bea7a1e

Please sign in to comment.