Dart Flashcards: Fundamentals
Dart — Fundamentals Flashcards
30 interactive flashcards covering core Dart concepts from null safety to Dart 3 features and Flutter basics. Press Space to flip, rate 1-4.
Additional Flashcard Topics
Null Safety:
Stringis non-nullable;String?is nullable. The?suffix,!(force unwrap),??(default), and?.(safe call) operators handle nullability.Async/Await:
asyncfunctions returnFuture<T>.awaitpauses execution until the Future completes.then()chains async operations. Error handling withtry-catch.Records (Dart 3):
(int, String)unnamed, fixed-size collections with named fields. Destructure withvar (a, b) = record.Patterns (Dart 3): switch expressions, destructuring, guards.
switch (shape) { Circle(r: var radius) => ... }.Mixins:
class A extends B with C, Dreuse code across class hierarchies. Mixins can declareonconstraints.Isolates: Dart’s concurrency model. Each isolate has its own memory and event loop. Communication via message passing. No shared state.
Intuition
Dart is a client-optimised language for building apps on any platform, it compiles to native code (AOT) for mobile and JavaScript for web. The single-threaded event loop model handles concurrency via async/await and Futures (similar to JavaScript Promises). Null safety, introduced in Dart 2.12, makes every variable non-nullable by default, the ? suffix marks nullable types, and late defers initialisation to runtime. Records and patterns (Dart 3) bring modern data modelling to the language. Dart is the language of Flutter, understanding Dart is essential for Flutter development.
Common Pitfalls
- Future timing: Starting an async operation without awaiting it, the code continues executing before the Future completes, causing race conditions. Use
awaitor chain with.then(). - Widget rebuilds: Rebuilding the entire widget tree on state changes in Flutter, use
constconstructors and targeted state management to minimise rebuilds. - Mixin ordering: When using
with A, Bthe last mixin’s methods take precedence, this can override earlier mixin methods unexpectedly if they share the same method name. - Late variable misuse:
latedefers initialisation but throwsLateInitializationErrorif accessed before being set. Use only when the variable cannot be initialised in the constructor. - Double vs double precision: Dart uses 64-bit doubles for all numbers.
intanddoubleare separate types,1.0is a double,1is an int.
Cross-References
- Dart Practice: Auto-graded problems that test the same concepts covered in these flashcards.
- Variables: Type specifiers, null safety, and collection types referenced in the flashcards.
- Async and Futures: Event loop and concurrency model covered in the async flashcards.
- Classes and Inheritance: OOP patterns including mixins and extension methods.
Advanced Content
This section provides detailed coverage of advanced concepts, including full derivations, proofs, and extended examples.
Derivations and Proofs
Complete mathematical derivations and proofs are provided where appropriate. Each step is explained to ensure understanding of the underlying reasoning.
Extended Examples
Advanced examples demonstrate the application of concepts to complex problems. These examples go beyond standard exam questions to develop deeper understanding.
Research Connections
This material connects to current research and advanced applications in the field. Understanding these connections provides context for the study material.
Prerequisites
Ensure you have mastered the prerequisite material before attempting this advanced content.