From fc05489cfeafa1638d6eeaaaf5d073ca73e1efe8 Mon Sep 17 00:00:00 2001 From: HamzaZaidiX Date: Wed, 27 Dec 2023 16:19:26 +0500 Subject: [PATCH] dosage textfield updated --- lib/home.dart | 2 + lib/medicationHomepage.dart | 5 +- lib/medication_reminder.dart | 459 ++++++++++-------- lib/services/AlarmSetupPage.dart | 31 +- pubspec.lock | 16 + pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 - windows/flutter/generated_plugins.cmake | 1 - 8 files changed, 308 insertions(+), 210 deletions(-) diff --git a/lib/home.dart b/lib/home.dart index a6f58e9..b4fe9d9 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -178,6 +178,7 @@ class Home extends StatelessWidget { title: Text("Homepage"), ), body: Center( + child: SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ @@ -214,6 +215,7 @@ class Home extends StatelessWidget { ], )), ), + ), ), ); } diff --git a/lib/medicationHomepage.dart b/lib/medicationHomepage.dart index 45febfc..a16a821 100644 --- a/lib/medicationHomepage.dart +++ b/lib/medicationHomepage.dart @@ -15,13 +15,12 @@ class medicationHomePage extends StatelessWidget { children: [ // Your app logo Image.asset( - 'assets/LOGO.png', - width: 175, + 'assets/LOGO.png', height: 175, ), Text( 'Press + to add a Reminder!', - style: TextStyle(fontSize: 18, color: Color.fromARGB(255, 81, 81, 82)), + style: TextStyle(fontSize: 20, color: Color.fromARGB(255, 81, 81, 82)), ), ], ), diff --git a/lib/medication_reminder.dart b/lib/medication_reminder.dart index 8db5aa3..e4d7841 100644 --- a/lib/medication_reminder.dart +++ b/lib/medication_reminder.dart @@ -2,8 +2,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:seizure_deck/services/notification_services.dart'; import 'package:flutter/services.dart'; -import 'package:http/http.dart' as http; -import 'dart:convert'; import 'package:timezone/data/latest.dart' as tz; import 'package:timezone/timezone.dart' as tz; import 'package:intl/intl.dart'; @@ -11,6 +9,8 @@ import '/services/AlarmSetupPage.dart'; import 'package:toggle_switch/toggle_switch.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; +enum MedicineType { Syrup, Tablets, Syringe } + class medicationReminder extends StatefulWidget { const medicationReminder({Key? key}) : super(key: key); @@ -32,7 +32,24 @@ class _medicationReminderWidgetState extends State { String selectedOption = 'Everyday'; - int selectedIndex = 0; + var label = 'Notification'; + + bool isSyrupSelected = false; + bool isTabletSelected = false; + bool isSyringeSelected = false; + +MedicineType selectedMedicine = MedicineType.Syrup; // Default medicine type + +String getHintText() { + switch (selectedMedicine) { + case MedicineType.Syrup: + return 'Enter dosage in ml/mg for syrup'; + case MedicineType.Tablets: + return 'Enter number of tablets'; + case MedicineType.Syringe: + return 'Enter syringe dosage in ml'; + } +} Future _scheduleNotification(DateTime scheduledTime) async { var androidPlatformChannelSpecifics = const AndroidNotificationDetails( @@ -80,10 +97,14 @@ class _medicationReminderWidgetState extends State { } TextEditingController textController = TextEditingController(); + final TextEditingController medicineController = TextEditingController(); +final TextEditingController dosageController = TextEditingController(); + DateTime? datePicked1; DateTime? datePicked2; @override Widget build(BuildContext context) { + var label; return Scaffold( appBar: AppBar( title: Text('Add New Medication'), @@ -112,6 +133,7 @@ class _medicationReminderWidgetState extends State { height: 15, ), TextField( + controller: medicineController, // Add the controller here decoration: InputDecoration( focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), @@ -128,45 +150,7 @@ class _medicationReminderWidgetState extends State { ), ), - // Textfield for Dosage - Padding( - padding: const EdgeInsets.only(top: 20.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - 'Dosage', - style: TextStyle( - color: Color(0xFF454587), - fontWeight: FontWeight.bold, - fontSize: 20, - ), - ), - const SizedBox( - height: 15, - ), - TextField( - keyboardType: TextInputType.number, - inputFormatters: [ - FilteringTextInputFormatter.digitsOnly, - ], - decoration: InputDecoration( - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(15.0), - borderSide: const BorderSide( - width: 2, color: Color(0xFF454587))), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(15.0), - borderSide: const BorderSide( - width: 2, color: Color(0xFF454587))), - hintText: ("Enter Dosage in ml"), - ), - ), - ], - ), - ), - - // Dropdown for Reminder Options + // Dropdown for Frequency Reminder Options Padding( padding: const EdgeInsets.only(top: 20.0), child: Column( @@ -207,83 +191,146 @@ class _medicationReminderWidgetState extends State { ), ), - Padding( + // IconButtons +Padding( padding: const EdgeInsets.only(top: 20.0), child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - 'Medicine Type', - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - color: Color(0xFF454587), - ), - ), - SizedBox(height: 10), // Adjust the spacing as needed - - Row( - mainAxisAlignment: MainAxisAlignment - .spaceEvenly, // Adjust this based on your spacing preference - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - IconButton( - icon: Icon(MdiIcons.medication), - onPressed: () { - // Add your functionality here - }, - iconSize: 30, // Set the icon size - ), - const SizedBox( - height: 10), // Adding a space of 10px - Text("Syrup"), - ], - ), - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - IconButton( - icon: Icon(MdiIcons.pill), - onPressed: () { - // Add your functionality here - }, - iconSize: 30, // Set the icon size - ), - const SizedBox( - height: 10), // Adding a space of 10px - Text("Tablets"), - ], - ), - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - IconButton( - icon: Icon(MdiIcons.needle), - onPressed: () { - // Add your functionality here - }, - iconSize: 30, // Set the icon size - ), - const SizedBox( - height: 10), // Adding a space of 10px - Text("Syringe"), - ], - ), - ], - ) - ], - ), - ), - - Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text( + 'Medicine Type', + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: Color(0xFF454587), + ), + ), + SizedBox(height: 10), +Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + IconButton( + icon: Icon( + MdiIcons.medication, + color: selectedMedicine == MedicineType.Syrup ? Colors.purple : Colors.grey, + ), + onPressed: () { + setState(() { + selectedMedicine = MedicineType.Syrup; + dosageController.clear(); + }); + }, + iconSize: 30, // Set the icon size + ), + const SizedBox(height: 10), + Text( + "Syrup", + style: TextStyle( + color: selectedMedicine == MedicineType.Syrup ? Colors.purple : Colors.grey, + ), + ), + ], + ), + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + IconButton( + icon: Icon( + MdiIcons.pill, + color: selectedMedicine == MedicineType.Tablets ? Colors.purple : Colors.grey, + ), + onPressed: () { + setState(() { + selectedMedicine = MedicineType.Tablets; + dosageController.clear(); + }); + }, + iconSize: 30, // Set the icon size + ), + const SizedBox(height: 10), + Text( + "Tablets", + style: TextStyle( + color: selectedMedicine == MedicineType.Tablets ? Colors.purple : Colors.grey, + ), + ), + ], + ), + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + IconButton( + icon: Icon( + MdiIcons.needle, + color: selectedMedicine == MedicineType.Syringe ? Colors.purple : Colors.grey, + ), + onPressed: () { + setState(() { + selectedMedicine = MedicineType.Syringe; + dosageController.clear(); + }); + }, + iconSize: 30, // Set the icon size + ), + const SizedBox(height: 10), + Text( + "Syringe", + style: TextStyle( + color: selectedMedicine == MedicineType.Syringe ? Colors.purple : Colors.grey, + ), + ), + ], + ), + ], +), + // Dosage Text Field +Padding( + padding: const EdgeInsets.only(top: 20.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'Dosage', + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: Color(0xFF454587), + ), + ), + TextField( + controller: dosageController, + keyboardType: TextInputType.number, + decoration: InputDecoration( + hintText: getHintText(), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(15.0), + borderSide: BorderSide( + width: 2, + color: Color(0xFF454587), + ), + ), + ), + ), + ], +), +), + ], +), +), + + // Select Date Button + Padding( + padding: const EdgeInsets.only(top: 20.0,right: 10.0), + child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - // Select Date Button + TextButton( onPressed: () async { final date = await showDatePicker( @@ -307,7 +354,7 @@ class _medicationReminderWidgetState extends State { borderRadius: BorderRadius.circular(15.0), // Button shape side: BorderSide( - width: 2, color: Color(0xFF454587)), // Border + width: 2, color: Color.fromARGB(255, 255, 255, 255)) ), ), child: const Text( @@ -360,7 +407,7 @@ class _medicationReminderWidgetState extends State { borderRadius: BorderRadius.circular(15.0), // Button shape side: BorderSide( - width: 2, color: Color(0xFF454587)), // Border + width: 2, color: Color.fromARGB(255, 255, 255, 255)), // Border ), ), child: const Text( @@ -373,100 +420,107 @@ class _medicationReminderWidgetState extends State { ), ], ), + ), // Toggle Switch for Reminder and Alarm - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - ToggleSwitch( - minWidth: 90.0, - minHeight: 36.0, - initialLabelIndex: 0, - activeBgColor: [Color(0xFF454587)], - labels: ['Reminder', 'Alarm'], - onToggle: (index) { - // Handle the toggle switch change - }, - ), - ElevatedButton( - child: const Text('Set Reminder'), - onPressed: () { - if (datePicked1 != null) { - // Compare the selected date with the current date and time - final currentTime = DateTime.now(); - if (datePicked1!.isAfter(currentTime)) { - // Format the date and time - String formattedDate = - DateFormat('dd/MM/yy').format(datePicked1!); - String formattedTime = - DateFormat('HH:mm').format(datePicked2!); +Padding( + padding: const EdgeInsets.only(top: 20.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ToggleSwitch( + minWidth: 100.0, + minHeight: 36.0, + initialLabelIndex: 0, + activeBgColor: [Color(0xFF454587)], + labels: ['Notification', 'Alarm'], + onToggle: (index) { + setState(() { + if (index == 0) { + // Notification is selected + ElevatedButton( + child: const Text('Set Notification'), + onPressed: () { + if (datePicked1 != null) { + // Compare the selected date with the current date and time + final currentTime = DateTime.now(); + if (datePicked1!.isAfter(currentTime)) { + // Format the date and time + String formattedDate = + DateFormat('dd/MM/yy').format(datePicked1!); + String formattedTime = + DateFormat('HH:mm').format(datePicked2!); - // The selected date is in the future, so set the reminder - NotificationService().showNotification( - title: 'Reminder', - body: - 'Your Reminder has been set for $formattedDate at $formattedTime', - ); - } else { - // The selected date is in the past, show an error message - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('Invalid Date'), - content: const Text( - 'Please select a future Date and Time to set a reminder!'), - actions: [ - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: const Text('OK'), - ), - ], - ); - }, - ); - } - } else { - // Handle the case where the date & time is not selected - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('Date Not Selected'), - content: const Text( - 'Please select a Date and Time to set a reminder.'), - actions: [ - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: const Text('OK'), - ), - ], - ); - }, + // The selected date is in the future, so set the notification + NotificationService().showNotification( + title: 'Notification', + body: + 'Your Notification has been set for $formattedDate at $formattedTime', + ); + } else { + // The selected date is in the past, show an error message + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('Invalid Date'), + content: const Text( + 'Please select a future Date and Time to set a Notification!'), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text('OK'), + ), + ], ); - } - }, - ), - ElevatedButton( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const AlarmSetupPage(), - ), + }, + ); + } + } else { + // Handle the case where the date & time is not selected + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('Date Not Selected'), + content: const Text( + 'Please select a Date and Time to set a Notification.'), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text('OK'), + ), + ], ); }, - child: const Text('Set Alarm'), - ), - ], + ); + } + }, + ); + } else { + // Alarm is selected + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const AlarmSetupPage(), ), + ); + } + }); + }, + ), + ], +), +), // Save Button - Column( + Padding( + padding: const EdgeInsets.only(top: 20.0), + child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( @@ -475,6 +529,7 @@ class _medicationReminderWidgetState extends State { ), ], ), + ), ], ), ), diff --git a/lib/services/AlarmSetupPage.dart b/lib/services/AlarmSetupPage.dart index e6979af..75ca8cf 100644 --- a/lib/services/AlarmSetupPage.dart +++ b/lib/services/AlarmSetupPage.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:file_picker/file_picker.dart'; import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart'; -import 'package:alarm/alarm.dart'; class AlarmSetupPage extends StatefulWidget { const AlarmSetupPage({Key? key}) : super(key: key); @@ -11,6 +11,7 @@ class AlarmSetupPage extends StatefulWidget { class _AlarmSetupPageState extends State { TimeOfDay selectedTime = TimeOfDay.now(); + String selectedRingtone = 'Default Ringtone'; Future _setAlarm() async { final now = DateTime.now(); @@ -43,6 +44,27 @@ class _AlarmSetupPageState extends State { // You can show a notification or perform other actions here } + Future _setRingtone() async { + try { + // Allow user to select an audio file + FilePickerResult? result = await FilePicker.platform.pickFiles( + type: FileType.audio, + allowMultiple: false, + ); + + if (result != null) { + String? filePath = result.files.single.path; + if (filePath != null) { + setState(() { + selectedRingtone = filePath; + }); + } + } + } catch (e) { + print('Error picking audio file: $e'); + } + } + @override Widget build(BuildContext context) { return Scaffold( @@ -77,6 +99,13 @@ class _AlarmSetupPageState extends State { onPressed: _setAlarm, child: const Text('Set Alarm'), ), + SizedBox(height: 20), + ElevatedButton( + onPressed: _setRingtone, + child: const Text('Select Ringtone'), + ), + SizedBox(height: 10), + Text('Selected Ringtone: $selectedRingtone'), ], ), ), diff --git a/pubspec.lock b/pubspec.lock index 06ccf3c..aae8190 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -161,6 +161,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.4" + file_picker: + dependency: "direct main" + description: + name: file_picker + sha256: "4e42aacde3b993c5947467ab640882c56947d9d27342a5b6f2895b23956954a6" + url: "https://pub.dev" + source: hosted + version: "6.1.1" flutter: dependency: "direct main" description: flutter @@ -254,6 +262,14 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0+1" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + sha256: b068ffc46f82a55844acfa4fdbb61fad72fa2aef0905548419d97f0f95c456da + url: "https://pub.dev" + source: hosted + version: "2.0.17" flutter_sensors: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index bd74289..1648509 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -71,6 +71,7 @@ dependencies: android_alarm_manager_plus: ^3.0.3 toggle_switch: ^2.1.0 material_design_icons_flutter: ^7.0.7296 + file_picker: ^6.1.1 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 4f78848..8b6d468 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,6 @@ #include "generated_plugin_registrant.h" -#include void RegisterPlugins(flutter::PluginRegistry* registry) { - UrlLauncherWindowsRegisterWithRegistrar( - registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 88b22e5..b93c4c3 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - url_launcher_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST