Skip to contentCategory · 10 tipsDart language
- 028Parse JSON safely with map patternsA switch on a map pattern checks keys and value types in one go, so bad JSON reaches your fallback case instead of a TypeError.json
- 024firstOrNull instead of try/catch on StateErrorfirst, firstWhere and single throw when nothing matches. The OrNull versions return null, and the type system makes you handle it.collections
- 021Skip nulls in collection literals with ...? and ?valueThe null-aware spread adds nothing for a null list, and a null-aware element leaves out a null entry, so you can drop the if (x != null).collections
- 019Extension types vs extension methodsAn extension method adds to a type. An extension type wraps it in a new static type, so a UserId can't be passed where an OrderId belongs.extension-types
- 016Await several futures with a record's .waitFuture.wait gives you a List of Object. A record of futures with .wait keeps each type and tells you which one failed.async
- 013Destructure lists with list patternsList patterns pull values out of a list by position, and a rest element skips or collects whatever sits in the middle.patterns
- 010Return multiple values with a recordA record returns two or more values without a throwaway class, and destructuring unpacks them in one line at the call site.records
- 008Switch on a record to match several values at oncePut two or three values in a record and switch on it. Each case is a row in a table, instead of a tangle of if/else.patterns
- 005A Result type with a sealed classReturn success or failure instead of throwing, and let an exhaustive switch make sure every caller handles both.sealed-classes
- 001Measure execution time with StopwatchDateTime.now() reads the wall clock, which can jump. Stopwatch can't, so use it to time code.performance
Keyboard shortcuts
- /
- Search
- r
- Random tip
- ← →
- Previous / next tip
- c
- Copy the first snippet
- p
- Debug paint on / off
- t
- Theme: system, light, dark
- ?
- This list