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 returningnullon error),tryIf(polling/retry until condition met),waitUntil, andlatestValidfor handling execution racing. - DevicePlatform: A unified API to detect platforms (iOS, Android, Windows, macOS, Linux, Web, Fuchsia) providing simple semantic checks like
isDesktop,isMobile, andisApple.
⏱️ Performance & Debugging
- Time Tracker: Robust
Trackermethods 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 andString.logextensions which guarantees printing strictly during Dart'skDebugModeto 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, andappend. - Time & Numbers: Fluid duration declarations on
num(e.g.,5.seconds,2.weeks) and powerfulDurationformatting/clamping logic. - Flutter Core Types: Includes
TextStyle.copyExcept(which drops specific properties), a robustTextSpan.copyWith, and calculation helpers onSize(canContain,add,multiply). - State & Enums: Simple boolean getters to intuitively assess Enum states from
AppLifecycleState,ConnectionState,TargetPlatform, andTextDirection(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!