updatePrinterStatus method

void updatePrinterStatus(
  1. String status,
  2. String color
)

Implementation

void updatePrinterStatus(String status, String color) {
  if (selectedAddress != null) {
    Color newColor = Colors.grey.withOpacity(0.6);
    switch (color) {
      case 'R':
        newColor = Colors.red;
        break;
      case 'G':
        newColor = Colors.green;
        break;
      default:
        newColor = Colors.grey.withOpacity(0.6);
        break;
    }
    final int index =
        _printers.indexWhere((element) => element.address == selectedAddress);
    _printers[index] = _printers[index].copyWith(
        status: status,
        color: newColor,
        isConnected: printers[index].address == selectedAddress);
    notifyListeners();
  }
}