Complete each lesson, attempt the exercise and compare with the worked answer.
Flutter and Dart essentials
Learn predictable state, asynchronous operations and safe model design.
Open coding playground Developer toolsNull safety
Dart distinguishes a non-nullable String from String?. Use a nullable type only when absence is meaningful. The null-coalescing operator provides a default; avoid force-unwrapping unless the invariant is proven.
Practice
Convert a nullable name to a non-null display label.
Review answer
final label = name ?? "Guest";
Async data loading
A Future represents a value that may arrive later. Use async/await and catch failures. Show loading, error and success separately. Do not block the UI while waiting for network or disk.
Practice
Write a pattern that awaits a repository call and handles failures.
Review answer
try { final data = await repository.load(); } catch (error) { /* emit error state */ }
State management
Keep input events, state transitions and UI rendering distinct. In BLoC or Cubit, emit an immutable state for each meaningful transition. Avoid triggering a fetch inside build repeatedly. Test state transitions independently.
Practice
Identify three states for a request.
Review answer
Loading, success with data, failure with error message.
