BooleanExtensions 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

Properties

isFalse → bool

Available on bool?, provided by the BooleanExtensions extension

Checks if the boolean value is false.
no setter
isNotFalse → bool

Available on bool?, provided by the BooleanExtensions extension

Checks if the boolean value is not false.
no setter
isNotTrue → bool

Available on bool?, provided by the BooleanExtensions extension

Checks if the boolean value is not true.
no setter
isTrue → bool

Available on bool?, provided by the BooleanExtensions extension

Checks if the boolean value is true.
no setter
toggle → bool

Available on bool?, provided by the BooleanExtensions extension

Toggles the boolean value.
no setter
toInt → int

Available on bool?, provided by the BooleanExtensions extension

Converts the boolean value to an integer.
no setter

Methods

validate({bool value = false}) → bool

Available on bool?, provided by the BooleanExtensions extension

Validates the given boolean value.