Skip to content

Commit

Permalink
feat: dynamic params
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlettau committed Jun 17, 2023
1 parent 18a4edd commit 5e16401
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .flutter-plugins

This file was deleted.

1 change: 0 additions & 1 deletion .flutter-plugins-dependencies

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ migrate_working_dir/
/pubspec.lock
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
build/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

- Dynamic parameters in bool utilities.

## 1.0.0

- Add bool utility functions.
16 changes: 12 additions & 4 deletions lib/src/boolean_utils.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/// Convert a boolean to an int.
int boolToInt(bool value) {
int boolToInt(dynamic value) {
if (value is int) {
return value;
}

return value ? 1 : 0;
}

/// Convert a boolean to an int, or null.
int? boolToIntOrNull(bool? value) {
int? boolToIntOrNull(dynamic value) {
if (value == null) {
return null;
}
Expand All @@ -13,12 +17,16 @@ int? boolToIntOrNull(bool? value) {
}

/// Convert an int to a boolean.
bool intToBool(int value) {
bool intToBool(dynamic value) {
if (value is bool) {
return value;
}

return value == 1 ? true : false;
}

/// Convert an int to a boolean, or null.
bool? intToBoolOrNull(int? value) {
bool? intToBoolOrNull(dynamic value) {
if (value == null) {
return null;
}
Expand Down
8 changes: 8 additions & 0 deletions test/src/boolean_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import 'package:sqflite_ext/sqflite_ext.dart';

void main() {
group('boolToInt', () {
test('returns int directly', () {
expect(boolToInt(0), 0);
});

test('returns 1 when true', () {
expect(boolToInt(true), 1);
});
Expand All @@ -20,6 +24,10 @@ void main() {
});

group('intToBool', () {
test('returns boolean directly', () {
expect(intToBool(false), false);
});

test('returns true when 1', () {
expect(intToBool(1), true);
});
Expand Down

0 comments on commit 5e16401

Please sign in to comment.