Esta página ainda não foi traduzida, por isso é exibida em inglês. Ajude a traduzir

predicates

A small family of type/value checks, kept around as tear-off-friendly functions for filter, takeWhile, and friends.

bool isNull(Object? a) bool isNotNull(Object? a) bool isNil(Object? a) // == isNull; Dart has no separate `undefined` bool isBool(Object? a) bool isNum(Object? a) bool isString(Object? a) bool isDateTime(Object? a) bool isList(Object? a) bool isMap(Object? a)

Lecture

In everyday Dart you'd just write a is String — that's idiomatic, and nothing here replaces it. These functions exist for one specific reason: Dart's is operator can't be torn off as a first-class function value, but filter, takeWhile, find, and friends all want a bool Function(A). filter(isString, mixedList) reads better than filter((a) => a is String, mixedList), and that's the whole point of this page.

isNil is a straight port of FxTS's "is null or undefined" check — since Dart collapses both into null, it's byte-for-byte identical to isNull. Three more names exist purely for FxTS parity and are marked @Deprecated: isUndefined (there's no undefined in Dart, so it's just isNull), isArray (JS Array → Dart List, so it's isList), and isObject (JS plain object → Dart Map, so it's isMap). Reach for the non-deprecated name in new code; the aliases are there so ported call sites still compile.

Demo 1 · Filter-friendly tear-offs

Demo 2 · isNil and the deprecated aliases

Try it yourself

Exercise: use isNotNull to filter the null out of row.

Related: filter — the usual place these get plugged in · isEmpty — a value-based check, not a type check · compact — drop nulls from an iterable · matches — a predicate for shape, not type