Search⌘ K
AI Features

Solution: Smart Thermostat Configuration

Explore how to implement a smart thermostat configuration function in Dart that uses named parameters with required and default values. Understand how to safely handle nullable inputs and control function calls, helping you write clear and maintainable code using Dart's function and scope features.

We'll cover the following...
Dart
void configureThermostat({required double targetTemp, String fanMode = 'auto', String? schedule}) {
print('Target: $targetTemp');
print('Fan: $fanMode');
if (schedule != null) {
print('Schedule: $schedule');
}
}
void main() {
configureThermostat(targetTemp: 72.5);
configureThermostat(targetTemp: 68.0, fanMode: 'on');
}

Solution explanation

In the main.dart file:

  • Line 1: We define ...