Advertisement
rajath_pai

BluetoothPairingRequest

Aug 4th, 2021
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.93 KB | None | 0 0
  1. part of flutter_bluetooth_serial;
  2.  
  3. /// Enum-like class for all types of pairing variants.
  4. class PairingVariant {
  5.   final int underlyingValue;
  6.  
  7.   const PairingVariant._(this.underlyingValue);
  8.  
  9.   factory PairingVariant.fromUnderlyingValue(int? value) {
  10.     switch (value) {
  11.       case 0:
  12.         return PairingVariant.Pin;
  13.       case 1:
  14.         return PairingVariant.Passkey;
  15.       case 2:
  16.         return PairingVariant.PasskeyConfirmation;
  17.       case 3:
  18.         return PairingVariant.Consent;
  19.       case 4:
  20.         return PairingVariant.DisplayPasskey;
  21.       case 5:
  22.         return PairingVariant.DisplayPin;
  23.       case 6:
  24.         return PairingVariant.OOB;
  25.       case 7:
  26.         return PairingVariant.Pin16Digits;
  27.       default:
  28.         return PairingVariant.Error;
  29.     }
  30.   }
  31.   int toUnderlyingValue() => underlyingValue;
  32.  
  33.   String toString() {
  34.     switch (underlyingValue) {
  35.       case 0:
  36.         return 'PairingVariant.Pin';
  37.       case 1:
  38.         return 'PairingVariant.Passkey';
  39.       case 2:
  40.         return 'PairingVariant.PasskeyConfirmation';
  41.       case 3:
  42.         return 'PairingVariant.Consent';
  43.       case 4:
  44.         return 'PairingVariant.DisplayPasskey';
  45.       case 5:
  46.         return 'PairingVariant.DisplayPin';
  47.       case 6:
  48.         return 'PairingVariant.OOB';
  49.       case 7:
  50.         return 'PairingVariant.Pin16Digits';
  51.       default:
  52.         return 'PairingVariant.Error';
  53.     }
  54.   }
  55.  
  56.   static const Error = PairingVariant._(-1);
  57.   static const Pin = PairingVariant._(0);
  58.   static const Passkey = PairingVariant._(1);
  59.   static const PasskeyConfirmation = PairingVariant._(2);
  60.   static const Consent = PairingVariant._(3);
  61.   static const DisplayPasskey = PairingVariant._(4);
  62.   static const DisplayPin = PairingVariant._(5);
  63.   static const OOB = PairingVariant._(6);
  64.   static const Pin16Digits = PairingVariant._(7);
  65.  
  66.   // operator ==(Object other) {
  67.   //   return other is PairingVariant && other.underlyingValue == this.underlyingValue;
  68.   // }
  69.  
  70.   // @override
  71.   // int get hashCode => underlyingValue.hashCode;
  72. }
  73.  
  74. /// Represents information about incoming pairing request
  75. class BluetoothPairingRequest {
  76.   /// MAC address of the device or identificator for platform system (if MAC addresses are prohibited).
  77.   final String? address;
  78.  
  79.   /// Variant of the pairing methods.
  80.   final PairingVariant? pairingVariant;
  81.  
  82.   /// Passkey for confirmation.
  83.   final int? passkey;
  84.  
  85.   /// Construct `BluetoothPairingRequest` with given values.
  86.   const BluetoothPairingRequest({
  87.     this.address,
  88.     this.pairingVariant,
  89.     this.passkey,
  90.   });
  91.  
  92.   /// Creates `BluetoothPairingRequest` from map.
  93.   /// Internally used to receive the object from platform code.
  94.   factory BluetoothPairingRequest.fromMap(Map map) {
  95.     return BluetoothPairingRequest(
  96.       address: map['address'],
  97.       pairingVariant: PairingVariant.fromUnderlyingValue(map['variant']),
  98.       passkey: map['passkey'],
  99.     );
  100.   }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement