// Removed: import 'dart:io' show stdin, stdout; // 'dart:io' is not supported by DartPad void main() { // ─────────────── Constants ─────────────── const int minTemp = 15; const int maxTemp = 30; // ─────────────── Device Status ─────────────── bool lightsOn = false; int thermostat = 20; bool securityArmed = false; // --- Simulate interactive input for DartPad --- // In a real console application, stdin.readLineSync() would be used. // For DartPad, we provide a sequence of simulated user choices. final List simulatedChoices = [ "1", // Toggle Lights "2", // Set Thermostat "25", // -> Input for thermostat temp (valid) "4", // View System Status "2", // Set Thermostat (invalid) "10", // -> Input for thermostat temp "3", // Arm Security "4", // View System Status "5", // Exit ]; int choiceIndex = 0; // ─────────────── Main Menu Loop ─────────────── // The loop now iterates through the simulated choices while (choiceIndex < simulatedChoices.length) { print("\n========= SMART HOME SYSTEM ========="); print("1. Toggle Lights"); print("2. Set Thermostat Temperature"); print("3. Arm/Disarm Security System"); print("4. View System Status"); print("5. Exit"); // Replaced stdout.write with print for DartPad compatibility print("Enter your choice (simulated): "); // Get the next simulated choice // simulatedChoices is List, so elements are guaranteed to be non-null Strings. String choice = simulatedChoices[choiceIndex]; print("Simulated input: $choice"); // Display the current simulated input choiceIndex++; // Move to the next simulated choice for the next iteration // The previous check `if (choice == null) continue;` is no longer needed // because `choice` is now declared as a non-nullable String, // reflecting that elements from `simulatedChoices` are never null. // ─────────────── Handling Choices ─────────────── switch (choice) { case "1": lightsOn = !lightsOn; print("Lights are now: ${lightsOn ? 'ON' : 'OFF'}"); break; case "2": // Replaced stdout.write with print for DartPad compatibility print("Enter temperature ($minTemp – $maxTemp) (simulated): "); // Check if there's a subsequent simulated input for temperature if (choiceIndex >= simulatedChoices.length) { print("No more simulated inputs for temperature. Skipping."); break; // Exit case "2" } String? tempInput = simulatedChoices[choiceIndex]; print("Simulated input for temperature: $tempInput"); choiceIndex++; // Move to the next simulated choice (for the next main menu choice) int? newTemp = int.tryParse(tempInput); // Input Validation if (newTemp == null || newTemp < minTemp || newTemp > maxTemp) { print( "❌ Invalid temperature! Must be between $minTemp and $maxTemp.", ); } else { thermostat = newTemp; print("✅ Thermostat set to $thermostat°C"); } break; case "3": securityArmed = !securityArmed; print( "Security System is now: ${securityArmed ? 'ARMED' : 'DISARMED'}", ); break; case "4": // FizzBuzz-like Temperature Message String tempMessage = ""; if (thermostat % 3 == 0 && thermostat % 5 == 0) { tempMessage = "Perfect Day"; } else if (thermostat % 3 == 0) { tempMessage = "Cool Day"; } else if (thermostat % 5 == 0) { tempMessage = "Warm Day"; } print("\n──── SYSTEM STATUS ────"); print("Lights: ${lightsOn ? 'ON' : 'OFF'}"); print( "Thermostat: $thermostat°C ${tempMessage.isNotEmpty ? '→ $tempMessage' : ''}", ); print("Security: ${securityArmed ? 'ARMED' : 'DISARMED'}"); break; case "5": print("Exiting Smart Home System... Goodbye!"); return; // Exits the main function after the simulated sequence default: print("❌ Invalid choice, please try again."); } } // If the loop finishes without a '5' choice, explicitly state it. if (choiceIndex >= simulatedChoices.length) { print("\nSimulated choices exhausted. Program finished."); } }