BooleanOrNullExtensions extension

A collection of boolean extension methods to simplify boolean operations.

This extension provides convenient methods to perform various operations on boolean values, such as validation, checking for true/false, toggling, and converting to integer values.

Example usage:

import 'package:flutter_helper_kit/flutter_helper_kit.dart';

void main() {
  // Example usage of boolean extensions
  bool? nullableBool = true;

  // Validate a boolean value and provide a default if null
  bool validatedValue = nullableBool.validate(value: false);
  print(validatedValue); // Output: true

  // Check if a boolean value is true
  print(nullableBool.isTrue); // Output: true

  // Check if a boolean value is false
  print(nullableBool.isFalse); // Output: false

  // Check if a boolean value is not true
  print(nullableBool.isNotTrue); // Output: false

  // Check if a boolean value is not false
  print(nullableBool.isNotFalse); // Output: true

  // Convert a boolean value to an integer (1 if true, 0 if false)
  int intValue = nullableBool.toInt;
  print(intValue); // Output: 1

  // Toggle the boolean value
  bool toggledValue = nullableBool.toggle;
  print(toggledValue); // Output: false
}
on

Methods

isFalse() bool

Available on bool?, provided by the BooleanOrNullExtensions extension

Checks if the boolean value is false.
isNotFalse() bool

Available on bool?, provided by the BooleanOrNullExtensions extension

Checks if the boolean value is not false.
isNotTrue() bool

Available on bool?, provided by the BooleanOrNullExtensions extension

Checks if the boolean value is not true.
isTrue() bool

Available on bool?, provided by the BooleanOrNullExtensions extension

Checks if the boolean value is true.
toggle() bool

Available on bool?, provided by the BooleanOrNullExtensions extension

Toggles the boolean value.
toInt() int

Available on bool?, provided by the BooleanOrNullExtensions extension

Converts the boolean value to an integer.
validate({bool value = false}) bool

Available on bool?, provided by the BooleanOrNullExtensions extension

Validates the given boolean value.