wifiLoginLogout function

Future<void> wifiLoginLogout()

Implementation

Future<void> wifiLoginLogout() async {
  try {
    print('=== WiFi Login/Logout ===');
    print('1. Login');
    print('2. Logout');
    stdout.write('Select option (1-2): ');

    final choice = stdin.readLineSync() ?? '';

    if (choice != '1' && choice != '2') {
      print('Invalid option.\n');
      return;
    }

    stdout.write('Enter username: ');
    final username = stdin.readLineSync() ?? '';

    stdout.write('Enter password: ');
    stdin.echoMode = false;
    final password = stdin.readLineSync() ?? '';
    stdin.echoMode = true;
    print('');

    if (username.isEmpty || password.isEmpty) {
      print('Username and password cannot be empty.\n');
      return;
    }

    final operation = choice == '1' ? 'login' : 'logout';
    final operationCode = choice == '1' ? 1 : 0;

    print('Performing WiFi $operation...');
    final (success, message) = await fetchWifi(
      username: username,
      password: password,
      i: operationCode,
    );

    if (success) {
      print('✓ WiFi $operation successful: $message\n');
    } else {
      print('✗ WiFi $operation failed: $message\n');
    }
  } catch (e) {
    print('Error with WiFi operation: $e\n');
  }
}