tezvyn:

Flutter & Dart

Flutter framework, Dart language, packages, Impeller

307 bites

More in Flutter & Dart — page 15

Flutter & Dart2 min read

StreamController: The Faucet for Your Data Stream

A StreamController is the faucet handle for your data stream. Use it to create a custom stream from any data source and push events to it. The main footgun is that a default controller only allows one listener; use `StreamController.broadcast` for multiple.

Flutter & Dart2 min read

Dart's Stream: Asynchronous Data Pipelines

Think of a Dart Stream as a conveyor belt for asynchronous data, delivering events over time. It's ideal for handling sequences like user input or file I/O.

Flutter & Dart2 min read

Future.wait: Run Concurrent Dart Operations

Run multiple async operations concurrently and collect their results in a single list. Use it to fire off independent tasks, like multiple network requests, and wait for them all to finish. The footgun: if one future fails, you lose all results by default.

Flutter & Dart2 min read

Dart Futures: Chaining Async Work with .then()

A Dart Future is a promise for a value that isn't ready yet. Chain actions onto it with .then() for success and .catchError() for failure. This is key for network requests or file I/O. The footgun is forgetting .catchError(), causing silent failures.

The Dart Event Loop: Your App's Task Manager
Flutter & Dart2 min read

The Dart Event Loop: Your App's Task Manager

The event loop is Dart's single-threaded task manager. It processes one event at a time from a queue (like user taps or network responses), preventing the UI from freezing. Use `async`/`await` to avoid blocking it with long operations.

The `covariant` Keyword: Loosening Type Rules
Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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')`.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart86 sec read

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
Flutter & Dart2 min read

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 `!`.

Flutter & Dart2 min read

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.