main
 1import 'package:blood_pressure_app/l10n/app_localizations.dart';
 2
 3/// Different modes for the bluetooth input field.
 4enum BluetoothInputMode {
 5  /// No bluetooth input.
 6  disabled,
 7  /// The established bluetooth input.
 8  oldBluetoothInput,
 9  /// The new bluetooth input with flutter_blue_plus backend.
10  newBluetoothInputOldLib,
11  /// The new bluetooth input with bluetooth_low_energy backend.
12  newBluetoothInputCrossPlatform;
13
14  /// Turn object into [deserialize]able number.
15  int serialize() => switch(this) {
16    BluetoothInputMode.disabled => 0,
17    BluetoothInputMode.oldBluetoothInput => 1,
18    BluetoothInputMode.newBluetoothInputOldLib => 2,
19    BluetoothInputMode.newBluetoothInputCrossPlatform => 3,
20  };
21
22  /// Try to create an object from [serialize]d form.
23  static BluetoothInputMode? deserialize(int? value) => switch (value) {
24    0 => BluetoothInputMode.disabled,
25    1 => BluetoothInputMode.oldBluetoothInput,
26    2 => BluetoothInputMode.newBluetoothInputOldLib,
27    3 => BluetoothInputMode.newBluetoothInputCrossPlatform,
28    _ => null,
29  };
30
31  /// Determine the matching localization.
32  String localize(AppLocalizations localizations) => switch(this) {
33    BluetoothInputMode.disabled => localizations.disabled,
34    BluetoothInputMode.oldBluetoothInput => localizations.oldBluetoothInput,
35    BluetoothInputMode.newBluetoothInputOldLib => localizations.newBluetoothInputOldLib,
36    BluetoothInputMode.newBluetoothInputCrossPlatform => localizations.newBluetoothInputCrossPlatform,
37  };
38}