manual health measurement command
This commit is contained in:
@@ -130,6 +130,31 @@ class _HealthScreenState extends ConsumerState<HealthScreen>
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
footer: _SaveSection()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SaveSection extends ConsumerWidget{
|
||||||
|
|
||||||
|
const _SaveSection();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final theme = ref.read(themePortProvider);
|
||||||
|
|
||||||
|
final vm = ref.read(healthViewModelProvider.notifier);
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 10),
|
||||||
|
child:
|
||||||
|
PrimaryButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await vm.measure();
|
||||||
|
},
|
||||||
|
text: context.translate(I18n.measure),
|
||||||
|
color: theme.getColorFor(ThemeCode.legacyPrimary)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,12 +14,14 @@ final healthViewModelProvider =
|
|||||||
|
|
||||||
class HealthViewModel extends Notifier<HealthViewState> {
|
class HealthViewModel extends Notifier<HealthViewState> {
|
||||||
late final HealthRepository _repository;
|
late final HealthRepository _repository;
|
||||||
|
late final CommandsRepository _commandsRepository;
|
||||||
|
|
||||||
static const int _historyPageSize = 20;
|
static const int _historyPageSize = 20;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
HealthViewState build() {
|
HealthViewState build() {
|
||||||
_repository = ref.read(healthRepositoryProvider);
|
_repository = ref.read(healthRepositoryProvider);
|
||||||
|
_commandsRepository = ref.read(commandsRepositoryProvider);
|
||||||
_init();
|
_init();
|
||||||
return const HealthViewState();
|
return const HealthViewState();
|
||||||
}
|
}
|
||||||
@@ -243,4 +245,32 @@ class HealthViewModel extends Notifier<HealthViewState> {
|
|||||||
final msg = e.toString();
|
final msg = e.toString();
|
||||||
return msg.startsWith('Exception: ') ? msg.substring(11) : msg;
|
return msg.startsWith('Exception: ') ? msg.substring(11) : msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> measure() async {
|
||||||
|
|
||||||
|
try {
|
||||||
|
state = state.copyWith(
|
||||||
|
isLoading: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
final device = ref.read(selectedDeviceProvider);
|
||||||
|
if (device == null) return;
|
||||||
|
|
||||||
|
final request = SendCommandRequestModel(
|
||||||
|
device: device.identificator,
|
||||||
|
command: DeviceCommand.requestHeartRate,
|
||||||
|
);
|
||||||
|
|
||||||
|
await _commandsRepository.send(request: request);
|
||||||
|
|
||||||
|
state = state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
state = state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
errorMessage: e.toString(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ enum DeviceCommand {
|
|||||||
factory,
|
factory,
|
||||||
@JsonValue('FIND_DEVICE')
|
@JsonValue('FIND_DEVICE')
|
||||||
findDevice,
|
findDevice,
|
||||||
|
@JsonValue('REQUEST_HEART_RATE')
|
||||||
|
requestHeartRate,
|
||||||
@JsonValue('RESTART')
|
@JsonValue('RESTART')
|
||||||
restart,
|
restart,
|
||||||
@JsonValue('REWARDS')
|
@JsonValue('REWARDS')
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ Map<String, dynamic> _$SendCommandRequestModelToJson(
|
|||||||
const _$DeviceCommandEnumMap = {
|
const _$DeviceCommandEnumMap = {
|
||||||
DeviceCommand.factory: 'FACTORY',
|
DeviceCommand.factory: 'FACTORY',
|
||||||
DeviceCommand.findDevice: 'FIND_DEVICE',
|
DeviceCommand.findDevice: 'FIND_DEVICE',
|
||||||
|
DeviceCommand.requestHeartRate: 'REQUEST_HEART_RATE',
|
||||||
DeviceCommand.restart: 'RESTART',
|
DeviceCommand.restart: 'RESTART',
|
||||||
DeviceCommand.rewards: 'REWARDS',
|
DeviceCommand.rewards: 'REWARDS',
|
||||||
DeviceCommand.shutdown: 'SHUTDOWN',
|
DeviceCommand.shutdown: 'SHUTDOWN',
|
||||||
|
|||||||
@@ -744,5 +744,6 @@
|
|||||||
"vibrationOnly": "Vibration only",
|
"vibrationOnly": "Vibration only",
|
||||||
"silent": "Silent",
|
"silent": "Silent",
|
||||||
"syncClockMessage": "Synchronize the device clock with the current time",
|
"syncClockMessage": "Synchronize the device clock with the current time",
|
||||||
"locationWifiNetworksOptional": "WiFi networks (optional)"
|
"locationWifiNetworksOptional": "WiFi networks (optional)",
|
||||||
|
"measure": "Measure"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -742,5 +742,6 @@
|
|||||||
"vibrationOnly": "Solo vibración",
|
"vibrationOnly": "Solo vibración",
|
||||||
"silent": "Silencio",
|
"silent": "Silencio",
|
||||||
"syncClockMessage": "Sincroniza el reloj del dispositivo con la hora actual",
|
"syncClockMessage": "Sincroniza el reloj del dispositivo con la hora actual",
|
||||||
"locationWifiNetworksOptional": "Redes WiFi (opcional)"
|
"locationWifiNetworksOptional": "Redes WiFi (opcional)",
|
||||||
|
"measure": "Medir"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -749,4 +749,5 @@ class I18n {
|
|||||||
static const String wifiSsid = 'wifiSsid';
|
static const String wifiSsid = 'wifiSsid';
|
||||||
static const String wifiSsidHint = 'wifiSsidHint';
|
static const String wifiSsidHint = 'wifiSsidHint';
|
||||||
static const String yesterday = 'yesterday';
|
static const String yesterday = 'yesterday';
|
||||||
|
static const String measure = 'measure';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user