Advertisement
rajath_pai

BluetoothBondState

Aug 4th, 2021
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.79 KB | None | 0 0
  1. part of flutter_bluetooth_serial;
  2.  
  3. class BluetoothBondState {
  4.   final int underlyingValue;
  5.   final String stringValue;
  6.  
  7.   const BluetoothBondState.fromString(String string)
  8.       : this.underlyingValue = (string == 'none'
  9.                 ? 10
  10.                 : string == 'bonding'
  11.                     ? 11
  12.                     : string == 'bonded'
  13.                         ? 12
  14.                         : -2 // Unknown, if not found valid
  15.             ),
  16.         this.stringValue =
  17.             ((string == 'none' || string == 'bonding' || string == 'bonded' //
  18.                 )
  19.                 ? string
  20.                 : 'unknown' // Unknown, if not found valid
  21.             );
  22.  
  23.   const BluetoothBondState.fromUnderlyingValue(int value)
  24.       : this.underlyingValue = ((value >= 10 && value <= 12)
  25.                 ? value
  26.                 : 0 // Unknown, if not found valid
  27.             ),
  28.         this.stringValue = (value == 10
  29.                 ? 'none'
  30.                 : value == 11
  31.                     ? 'bonding'
  32.                     : value == 12
  33.                         ? 'bonded'
  34.                         : 'unknown' // Unknown, if not found valid
  35.             );
  36.  
  37.   String toString() => 'BluetoothBondState.$stringValue';
  38.  
  39.   int toUnderlyingValue() => underlyingValue;
  40.  
  41.   static const unknown = BluetoothBondState.fromUnderlyingValue(0);
  42.   static const none = BluetoothBondState.fromUnderlyingValue(10);
  43.   static const bonding = BluetoothBondState.fromUnderlyingValue(11);
  44.   static const bonded = BluetoothBondState.fromUnderlyingValue(12);
  45.  
  46.   operator ==(Object other) {
  47.     return other is BluetoothBondState &&
  48.         other.underlyingValue == this.underlyingValue;
  49.   }
  50.  
  51.   @override
  52.   int get hashCode => underlyingValue.hashCode;
  53.  
  54.   bool get isBonded => this == bonded;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement