bs_utils

bs_utils is a lightweight, multipurpose Flutter and Dart utility package that provides a broad collection of extensions, performance trackers, and convenience wrapper methods to accelerate daily development.

Note: This package is actively used as a core foundational dependency for the "BS Collection" packages (such as bs_l10n, bs_overlay, etc.).

Overview

The package is structurally divided to target several domains: Core Utilities, Performance & Debugging, and Syntactic Sugar Extensions.

⚙️ Core Utilities

  • MethodsUtils: Handle advanced functional needs with elegant wrappers like tryThis (safe execution returning null on error), tryIf (polling/retry until condition met), waitUntil, and latestValid for handling execution racing.
  • DevicePlatform: A unified API to detect platforms (iOS, Android, Windows, macOS, Linux, Web, Fuchsia) providing simple semantic checks like isDesktop, isMobile, and isApple.

⏱️ Performance & Debugging

  • Time Tracker: Robust Tracker methods to measure execution time of both asynchronous and synchronous functions (trackSync, trackAsync), as well as helper methods to directly compare their performance (compareSync, compareAsync, compare).
  • True Debug Print: Provides the dprint() snippet and String.log extensions which guarantees printing strictly during Dart's kDebugMode to avoid console clutter in release builds.

🧩 Useful Extensions

Rich extensions provided on common Dart and Flutter classes over diverse sectors:

  • Iterables: Discover min/max elements naturally via maxOf, allMaxOf, minOf, and append.
  • Time & Numbers: Fluid duration declarations on num (e.g., 5.seconds, 2.weeks) and powerful Duration formatting/clamping logic.
  • Flutter Core Types: Includes TextStyle.copyExcept (which drops specific properties), a robust TextSpan.copyWith, and calculation helpers on Size (canContain, add, multiply).
  • State & Enums: Simple boolean getters to intuitively assess Enum states from AppLifecycleState, ConnectionState, TargetPlatform, and TextDirection (e.g., .isResumed, .isDone, .isAndroid).

Issues & Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page. To contribute, fork the repository at https://github.com/B-Saeid/bs_utils and submit a pull request.


Enjoy a cleaner codebase, write less boilerplate!