Agent skill
check-if-an-object-is-truthy-in-dart
Learn how to extend Dart's functionality to implement JavaScript-style "truthy" checks for easier conditional logic and value evaluations.
Install this agent skill to your Project
npx add-skill https://github.com/rodydavis/skills/tree/main/skills/dart_truthy
Metadata
Additional technical details for this skill
- last modified
- Tue, 03 Feb 2026 20:04:34 GMT
SKILL.md
Check if an Object is Truthy in Dart
If you are coming from language like JavaScript you may be used to checking if an object is truthy.
if (true)
if ({})
if ([])
if (42)
if ("0")
if ("false")
if (new Date())
if (-42)
if (12n)
if (3.14)
if (-3.14)
if (Infinity)
if (-Infinity)
In Dart you need to explicitly check if an object is not null, true/false or determine if the value is true based on the type.
It is possible however to use Dart extensions to add the truthy capability.
extension on Object? {
bool get isTruthy => truthy(this);
}
bool truthy(Object? val) {
if (val == null) return false;
if (val is bool) return val;
if (val is num && val == 0) return false;
if (val is String && (val == 'false' || val == '')) return false;
if (val is Iterable && val.isEmpty) return false;
if (val is Map && val.isEmpty) return false;
return true;
}
This will now make it possible for any object to be evaluated as a truthy value in if statements or value assignments.
Prints the following:
(null, false)
(, false)
(false, false)
(true, true)
(0, false)
(1, true)
(false, false)
(true, true)
([], false)
([1, 2, 3], true)
({}, false)
({1, 2, 3}, true)
({a: 1, b: 2}, true)
Demo
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
how-to-do-offline-recommendations-with-sqlite-and-gemini
Learn how to enhance your CMS like PocketBase with AI-powered content recommendations using text embeddings, SQLite, and k-nearest neighbor search for efficient and scalable related content suggestions.
how-to-build-a-webrtc-signal-server-with-pocketbase
Learn how to build a simple WebRTC video call application using PocketBase as a signaling server, enabling peer-to-peer communication with SQLite on the server and realtime updates via Server Sent Events.
flutter-terminal-cheat-sheet
This post provides a handy collection of Flutter commands and scripts for web development, package creation, troubleshooting, testing, and more, streamlining your Flutter workflow.
how-to-print-multiple-objects-to-the-console-with-print-in-dart
Learn how to print multiple objects to the console in Dart using Records, offering a similar experience to JavaScript's `console.log()` functionality.
flutter-input-output-preview
Build responsive Flutter apps with a reusable `TwoPane` widget and an `InputOutputPreview` component for side-by-side code and preview display on both mobile and desktop.
displaying-html-in-flutter
Easily display and interact with HTML content in your Flutter app using the `easy_web_view` package, which supports both web and mobile platforms.
Didn't find tool you were looking for?