All bites
The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.
8667 bites
Page 340

The `covariant` Keyword: Loosening Type Rules
The covariant keyword tells Dart's analyzer to relax its strict rules for method overriding, letting a subclass method accept a more specific parameter type. It's often used in Flutter widgets.
Extension Methods: Add to Classes You Don't Own
Extension methods let you add functionality to existing classes you don't control. Use them to create fluent APIs, like calling '42'.parseInt() instead of int.parse('42').
Dart Mixins: Constraining Reusable Code with `on`
A Dart mixin is like a plugin of methods for a class. The on keyword acts as a gatekeeper, ensuring the class using the mixin already has specific base features. This is used for sharing UI logic only among Widget subclasses.
Dart's Enhanced Enums: More Than Just Constants
An enhanced enum is a class with a fixed set of instances. It lets you add fields, methods, and constructors to your enums, turning them from simple labels into powerful objects with attached data and behavior.
Why hashCode and operator== Must Be Overridden Together
Overriding == without hashCode breaks collections like Set and Map. If two objects are equal, they MUST have the same hash code. This is vital for custom classes used as map keys or set elements.
Dart: Abstract Classes & Implicit Interfaces
An abstract class is a blueprint that other classes must follow, but it can't be instantiated itself. Dart also lets any class act as an 'implicit interface,' forcing other classes to implement its public API without inheritance.
Dart's Specialized Constructors: Named, Factory, and Constant
Dart constructors offer more than one way to create an object. Use named constructors for clarity (e.g., fromJSON), factory for caching or returning subtypes, and const for compile-time constant objects.
Dart's Lazy Iterable Methods: map() and where()
Think of map() or where() not as instant transformations, but as recipes for a new list. They're lazy, only doing work when you iterate. Use them to chain operations without creating intermediate lists.
Static Members: Belong to the Class, Not the Instance
A static member is shared across all instances of a class, belonging to the class itself. Use it for constants or utility functions that don't depend on an instance's state, like a global counter. The footgun: you cannot use this inside a static context.
Dart Streams: Asynchronous Data Sequences
A Dart Stream is like a conveyor belt for asynchronous data, delivering events or file chunks as they arrive. Use them for continuous data flows like button clicks or reading large files.
Dart Generics: Type-Safe Containers and Reusable Code
Generics let you define code that works with multiple types without sacrificing type safety. A List<String> is a list that only accepts strings. This is essential for collections.
Dart's async/await: Non-Blocking Code That Reads Synchronously
Dart's async/await makes non-blocking code read like a simple script. Use it for network requests or file I/O to keep your UI from freezing. The biggest footgun is calling an async function but forgetting to await its Future result.
Dart's Cascade Notation: Chain Calls on One Object
Cascade notation (..) lets you perform a sequence of operations on the same object without repeating its name. It's ideal for configuring new instances in one block.

Dart's Null-Aware Operators: Safely Handle Nulls
Null-aware operators let you work with potentially null values without a cascade of if (x != null) checks. Use them to access properties, provide defaults, or assign values only when a variable is null. The footgun is confusing safe ?. with unsafe !.
Dart's Sound Null Safety: No More Null Errors
In Dart, variables can't be null unless you explicitly allow it. This flips the usual model, turning potential runtime null pointer crashes into compile-time errors you can fix immediately.
Dart Collections: Choosing List, Set, or Map
Dart collections organize data: use a List for ordered items, a Set for unique items, and a Map for key-value pairs. This choice is fundamental for storing UI widgets or parsing JSON. The common footgun is using a List for lookups, which is slow; use.
Dart Function Syntax: Block Body vs. Arrow Notation
Dart functions use a block body {} for multiple statements or arrow syntax => for a single expression. Use => for simple one-liners like bool isEven(int n) => n % 2 == 0;. The footgun is using => for multi-step logic; it only works for.
Dart's Control Flow: Telling Your Code What to Do Next
Control flow statements are the road signs for your code, directing execution beyond a simple top-to-bottom path. Use if/else for decisions, for/while for loops, and try/catch to handle errors. The footgun is forgetting break in a switch case.
Dart's Core Data Types: Everything is an Object
In Dart, everything is an object, from numbers to functions. This means even a simple int or String has methods and properties, unlike primitive types in other languages. The main footgun is forgetting that null itself is a type, Null.
Dart Variables: var, final, and const
In Dart, var creates a mutable variable, while final and const are for single-assignment. Use var for changing state, final for runtime values set once, and const for compile-time constants. The footgun is confusing final with const.