From 4f8cc712ec0a0309848dc301878bbe0cb0afaa24 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Tue, 4 Oct 2022 15:51:20 +0530 Subject: [PATCH 1/2] feat: added receiver edit ability --- .../iot_receiver/lib/forms/receiver_form.dart | 27 +++-- .../lib/screens/receivers_screen.dart | 102 ++++++++++-------- .../lib/widgets/new_receiver_dialog.dart | 15 +-- 3 files changed, 82 insertions(+), 62 deletions(-) diff --git a/flutter/iot_receiver/lib/forms/receiver_form.dart b/flutter/iot_receiver/lib/forms/receiver_form.dart index d90cb64b..17bb7e4f 100644 --- a/flutter/iot_receiver/lib/forms/receiver_form.dart +++ b/flutter/iot_receiver/lib/forms/receiver_form.dart @@ -5,10 +5,13 @@ import 'package:auto_size_text/auto_size_text.dart'; // Some Form templates to reuse in New and Edit for devices -FormBuilderDropdown receiverDeviceSelector(BuildContext context, items) { +FormBuilderDropdown receiverDeviceSelector(BuildContext context, items, + {dynamic initialValue} + ) { return FormBuilderDropdown( name: "device_selector", items: items, + initialValue: initialValue, decoration: const InputDecoration( // labelText: 'Select Device', // labelStyle: TextStyle(fontWeight: FontWeight.bold), @@ -18,9 +21,10 @@ FormBuilderDropdown receiverDeviceSelector(BuildContext context, items) { } FormBuilderTextField receiverAtsignForm( - BuildContext context, String initialValue) { + BuildContext context, {String? initialValue} + ) { return FormBuilderTextField( - initialValue: initialValue.toString(), + initialValue: initialValue?.toString(), name: '@receiver', decoration: const InputDecoration( labelText: 'Receiver\'s atSign', @@ -33,9 +37,10 @@ FormBuilderTextField receiverAtsignForm( } FormBuilderTextField receiverShortnameForm( - BuildContext context, String initialValue) { + BuildContext context, {String? initialValue} + ) { return FormBuilderTextField( - initialValue: initialValue.toString(), + initialValue: initialValue?.toString(), name: 'shortName', decoration: const InputDecoration( labelText: 'Patient ID', @@ -47,22 +52,26 @@ FormBuilderTextField receiverShortnameForm( style: const TextStyle(fontSize: 20, letterSpacing: 5)); } -FormBuilderCheckbox sendHRForm(BuildContext context, String initialValue) { +FormBuilderCheckbox sendHRForm(BuildContext context, + {bool? initialValue} + ) { return FormBuilderCheckbox( name: 'sendHR', title: const Text('Send Heart Rate', style: TextStyle(fontWeight: FontWeight.bold)), - initialValue: false, + initialValue: initialValue ?? false, tristate: false, ); } -FormBuilderCheckbox sendO2Form(BuildContext context, String initialValue) { +FormBuilderCheckbox sendO2Form(BuildContext context, + {bool? initialValue} + ) { return FormBuilderCheckbox( name: 'sendO2', title: const Text('Send Oxygen Saturation', style: TextStyle(fontWeight: FontWeight.bold)), - initialValue: false, + initialValue: initialValue ?? false, tristate: false, ); } diff --git a/flutter/iot_receiver/lib/screens/receivers_screen.dart b/flutter/iot_receiver/lib/screens/receivers_screen.dart index f788d8eb..200ae984 100644 --- a/flutter/iot_receiver/lib/screens/receivers_screen.dart +++ b/flutter/iot_receiver/lib/screens/receivers_screen.dart @@ -64,54 +64,62 @@ class _ReceiversScreenState extends State { padding: EdgeInsets.only(right: 16), child: Icon(Icons.delete), )); - return Dismissible( - key: Key(receiver.receiverAtsign), - background: Container( - color: Colors.red, - child: align, - ), - confirmDismiss: (direction) async { - if (direction == DismissDirection.startToEnd) { - return false; - } else { - bool delete = true; - final snackbarController = - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - 'Delete ${receiver.receiverAtsign} ?'), - action: SnackBarAction( - label: 'Cancel', - onPressed: () => delete = false), - ), - ); - await snackbarController.closed; - return delete; - } - }, - onDismissed: (_) async { - hrO2ReceiverList.remove(receiver); - await _hrO2DataService.deleteReceiver(receiver); - setState(() {}); + return GestureDetector( + onTap: () async{ + await Navigator.push( + context, + MaterialPageRoute(builder: (context) => NewHrO2Receiver(hrO2Receiver: receiver,)), + ); }, - child: ListTile( - shape: RoundedRectangleBorder( - side: const BorderSide( - color: Colors.blue, width: 1), - borderRadius: BorderRadius.circular(10)), - title: - Text(hrO2ReceiverList[index].receiverAtsign), - subtitle: Text((hrO2ReceiverList[index].sendHR - ? "sending heart rate" - : "") + - (hrO2ReceiverList[index].sendHR && - hrO2ReceiverList[index].sendO2 - ? ", and " - : "") + - (hrO2ReceiverList[index].sendO2 - ? "sending o2 saturation" - : "")), - // trailing: const Icon(Icons.navigate_next), + child: Dismissible( + key: Key(receiver.receiverAtsign), + background: Container( + color: Colors.red, + child: align, + ), + confirmDismiss: (direction) async { + if (direction == DismissDirection.startToEnd) { + return false; + } else { + bool delete = true; + final snackbarController = + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + 'Delete ${receiver.receiverAtsign} ?'), + action: SnackBarAction( + label: 'Cancel', + onPressed: () => delete = false), + ), + ); + await snackbarController.closed; + return delete; + } + }, + onDismissed: (_) async { + hrO2ReceiverList.remove(receiver); + await _hrO2DataService.deleteReceiver(receiver); + setState(() {}); + }, + child: ListTile( + shape: RoundedRectangleBorder( + side: const BorderSide( + color: Colors.blue, width: 1), + borderRadius: BorderRadius.circular(10)), + title: + Text(hrO2ReceiverList[index].receiverAtsign), + subtitle: Text((hrO2ReceiverList[index].sendHR + ? "sending heart rate" + : "") + + (hrO2ReceiverList[index].sendHR && + hrO2ReceiverList[index].sendO2 + ? ", and " + : "") + + (hrO2ReceiverList[index].sendO2 + ? "sending o2 saturation" + : "")), + // trailing: const Icon(Icons.navigate_next), + ), ), ); }), diff --git a/flutter/iot_receiver/lib/widgets/new_receiver_dialog.dart b/flutter/iot_receiver/lib/widgets/new_receiver_dialog.dart index 562fda44..bc7d3ceb 100644 --- a/flutter/iot_receiver/lib/widgets/new_receiver_dialog.dart +++ b/flutter/iot_receiver/lib/widgets/new_receiver_dialog.dart @@ -11,7 +11,8 @@ import 'package:iot_receiver/services/hro2_data_service.dart'; import 'package:new_gradient_app_bar/new_gradient_app_bar.dart'; class NewHrO2Receiver extends StatefulWidget { - const NewHrO2Receiver({Key? key}) : super(key: key); + final HrO2Receiver? hrO2Receiver; + const NewHrO2Receiver({Key? key, this.hrO2Receiver}) : super(key: key); static const String id = '/new_receiver'; @override @@ -104,15 +105,17 @@ class _NewHrO2ReceiverState extends State { value: device, child: Text(device.deviceAtsign), )) - .toList()); + .toList(), + initialValue: widget.hrO2Receiver?.hrO2Device, + ); } else { return const Text("loading"); } })), - receiverShortnameForm(context, ''), - receiverAtsignForm(context, ''), - sendHRForm(context, ''), - sendO2Form(context, ''), + receiverShortnameForm(context, initialValue: widget.hrO2Receiver?.receiverShortname), + receiverAtsignForm(context, initialValue: widget.hrO2Receiver?.receiverAtsign), + sendHRForm(context, initialValue: widget.hrO2Receiver?.sendHR), + sendO2Form(context, initialValue: widget.hrO2Receiver?.sendO2), Row( children: [ const SizedBox(width: 20), From 7effbd646a1784118d5714384ba305b5471271db Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Tue, 4 Oct 2022 16:42:53 +0530 Subject: [PATCH 2/2] fix: added missing await whle deleting --- flutter/iot_receiver/lib/services/hro2_data_service.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter/iot_receiver/lib/services/hro2_data_service.dart b/flutter/iot_receiver/lib/services/hro2_data_service.dart index 8708aef7..63aa9edf 100644 --- a/flutter/iot_receiver/lib/services/hro2_data_service.dart +++ b/flutter/iot_receiver/lib/services/hro2_data_service.dart @@ -124,7 +124,7 @@ class Hro2DataService { HrO2Receiver rec = HrO2Receiver.fromJson(atKeyString); if (rec.receiverAtsign == hrO2Receiver.receiverAtsign) { _logger.info('deleteReceiver deleting ${hrO2Receiver.receiverAtsign}\'s entry'); - delete(key); + await delete(key); } } return true;