ObjectFinder is a powerful Dart extension on Object? that simplifies safe type checking, dynamic value conversion, and nested object access with default values. It supports primitives, lists, maps, and custom conversion via builders.

Features

  • ✅ Check object validity (isValid, isNotValid)
  • ✅ Detect types (isMap, isList, isListOfMap)
  • ✅ Safe equality comparison (equals)
  • ✅ Convert dynamic values to int, double, String, bool, num or List
  • ✅ Retrieve nested map data safely (find, findOrNull, finds, findsOrNull, get, getOrNull)
  • ✅ Supports optional custom conversion via ObjectBuilder

Usage

import 'package:object_finder/object_finder.dart';

void main() {
  final Map<String, dynamic> userData = {
    "id": "101",
    "active": "true",
    "balance": "250.75",
    "tags": ["vip", "loyal"],
    "purchases": [
      {"item": "Book", "price": "12.99"},
      {"item": "Pen", "price": "2.50"},
    ]
  };

  // ✅ Basic conversions
  final int id = userData.find<int>(key: "id"); // → 101
  final bool active = userData.find<bool>(key: "active"); // → true
  final double balance = userData.find<double>(key: "balance"); // → 250.75

  // ✅ List conversions
  final tags = userData.finds<String>(key: "tags"); // → ["vip", "loyal"]

  // ✅ List of map handling
  final purchases = userData.finds<Map<String, dynamic>>(key: "purchases");
  final firstItem = purchases.first.find<String>(key: "item"); // → "Book"
  final firstPrice = purchases.first.find<double>(key: "price"); // → 12.99

  // ✅ Default values
  final nickname = userData.findOrNull<String>(
      key: "nickname", defaultValue: "Guest"); // → "Guest"

  print('ID: $id');
  print('Active: $active');
  print('Balance: $balance');
  print('Tags: $tags');
  print('First item: $firstItem');
  print('First price: $firstPrice');
  print('Nickname: $nickname');
}

✨ Highlights:

  • Converts dynamic strings into strongly typed values.
  • Handles nested maps and lists effortlessly.
  • Provides safe defaults and type builders.
  • Works great for parsing JSON or remote API data.

Libraries

object_finder