diff --git a/lib/Screens/Calendar.dart b/lib/Screens/Calendar.dart index dcd43cb..70d41f2 100644 --- a/lib/Screens/Calendar.dart +++ b/lib/Screens/Calendar.dart @@ -1,4 +1,6 @@ +import 'dart:async'; import 'dart:convert'; +import 'dart:core'; import 'package:activmind_app/Screens/HomeForm.dart'; import 'package:activmind_app/Screens/appsettingpage.dart'; import 'package:activmind_app/Screens/locationList.dart'; @@ -11,15 +13,22 @@ import '../common/csrf.dart'; import '../common/task_class.dart'; import 'package:intl/intl.dart'; import 'package:logger/logger.dart'; +import 'createtask.dart'; var logger = Logger( - level: Level.all + level: Level.all ); - +extension TimeOfDayExtension on TimeOfDay { + String formatHHmm24() { + return '${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}'; + } +} class Calendar extends StatefulWidget { - const Calendar({super.key}); + + final DateTime? selectedDay; + const Calendar({super.key, this.selectedDay}); @override State createState() => __CalendarState(); @@ -33,11 +42,13 @@ class __CalendarState extends State { DateTime selectedDay = DateTime.now(); String selectedDayFormatted = DateFormat('yyyy-MM-dd').format(DateTime.now()); + String selectedDayFormatted2 = DateFormat('MM-dd-yyyy').format(DateTime.now()); void _selectDay(DateTime day) { setState(() { selectedDay = day; selectedDayFormatted = DateFormat('yyyy-MM-dd').format(selectedDay); + selectedDayFormatted2 = DateFormat('MM-dd-yyyy').format(selectedDay); }); fetchTasks(selectedDayFormatted); } @@ -49,12 +60,20 @@ class __CalendarState extends State { @override void initState() { super.initState(); - final DateTime now = DateTime.now(); - final DateFormat formatter = DateFormat('yyyy-MM-dd'); - final String formattedDate = formatter.format(now); - fetchTasks(formattedDate); + if (widget.selectedDay != null) { + selectedDay = widget.selectedDay!; + selectedDayFormatted = DateFormat('yyyy-MM-dd').format(selectedDay); + selectedDayFormatted2 = DateFormat('MM-dd-yyyy').format(selectedDay); + fetchTasks(selectedDayFormatted); + } else { + final DateTime now = DateTime.now(); + final DateFormat formatter = DateFormat('yyyy-MM-dd'); + final String formattedDate = formatter.format(now); + fetchTasks(formattedDate); + } } + Future fetchTasks(String date) async { SharedPreferences prefs = await SharedPreferences.getInstance(); @@ -83,135 +102,24 @@ class __CalendarState extends State { } } - - // void showFormDialog(BuildContext context, GlobalKey formKey) { - // showDialog( - // context: context, - // builder: (BuildContext context) { - // return AlertDialog(backgroundColor: const Color.fromARGB(255, 209, 193, 238), - // content: Stack( - // clipBehavior: Clip.none, - // children: [ - // Positioned( - // right: -40, - // top: -40, - // child: InkResponse( - // onTap: () { - // Navigator.of(context).pop(); - // }, - // child: const CircleAvatar( - // backgroundColor: Colors.red, - // child: Icon(Icons.close), - // ), - // ), - // ), - // Form( - // key: _formKey, - // child: Column( - // mainAxisSize: MainAxisSize.min, - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // const Padding( - // padding: EdgeInsets.all(8), - // child: Text( - // 'Nom de l’activité', - // textAlign: TextAlign.left, - // style: TextStyle( - // fontSize: 16.0, - // color: Color.fromARGB(255, 23, 79, 124), - // ), - // ), - // ), - // const Padding( - // padding: EdgeInsets.all(8), - // child: TextField( - // keyboardType: TextInputType.multiline, - // maxLines: null, - // decoration: InputDecoration( - // hintText: - // 'Veuillez entrer un nom de l\'activité ', - // border: OutlineInputBorder(), - // fillColor: - // Color.fromARGB(255, 232, 217, 255), - // filled: true, - // ), - // ), - // ), - // const Padding( - // padding: EdgeInsets.all(8), - // child: Text( - // 'Description (optionnel)', - // textAlign: TextAlign.left, - // style: TextStyle( - // fontSize: 16.0, - // color: Color.fromARGB(255, 23, 79, 124), - // ), - // ), - // ), - // const Padding( - // padding: EdgeInsets.all(8), - // child: TextField( - // keyboardType: TextInputType.multiline, - // maxLines: 3, - // decoration: InputDecoration( - // hintText: - // 'Si vous voulez, vous pouvez entrer votre description (c\'est optionnel)', - // border: OutlineInputBorder(), - // fillColor: - // Color.fromARGB(255, 232, 217, 255), - // filled: true, - // ), - // ), - // ), - // Row( - // crossAxisAlignment: CrossAxisAlignment.center, - // children: [ - // Padding( - // padding: const EdgeInsets.only( - // left: 10, top: 10), - // child: ElevatedButton( - // style: ElevatedButton.styleFrom( - // foregroundColor: const Color.fromARGB( - // 255, 255, 255, 255), backgroundColor: const Color.fromARGB(255, 65, 64, 155), - // ), - // onPressed: () { - // if (_formKey.currentState! - // .validate()) { - // _formKey.currentState!.save(); - // Navigator.of(context).pop(); - // } - // }, - // child: const Text('Annuler'), - // ), - // ), - // const Spacer(), - // Padding( - // padding: const EdgeInsets.only(top: 10), - // child: ElevatedButton( - // style: ElevatedButton.styleFrom( - // foregroundColor: const Color.fromARGB(255, 44, 41, 223), backgroundColor: const Color.fromARGB(255, 255, 181, 70), - // ), - // onPressed: () { - // if (_formKey.currentState! - // .validate()) { - // _formKey.currentState!.save(); - // } - // }, - // child: const Text('Enregistrer'), - // ), - // ), - // ], - // ), - // ], - // ), - // ), - // ], - // ), - // ); - // }, - // ); - // } - + Future deleteTask(int id) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + final token = prefs.getString('token'); + final csrfToken = await fetchCSRFToken(); + final response = await http.delete( + Uri.parse('http://10.0.2.2:8000/tasks/$id/'), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Token $token', + 'X-CSRFToken': csrfToken, + } + ); + if (response.statusCode == 204) { + fetchTasks(selectedDayFormatted); + } else { + throw Exception('Failed to delete task'); + } + } int _currentIndex = 1; @@ -257,7 +165,8 @@ class __CalendarState extends State { } - @override + +@override Widget build(BuildContext context) { Widget currentPage; switch (_currentIndex) { @@ -282,8 +191,9 @@ class __CalendarState extends State { body: SingleChildScrollView( child: Column( children: [ + const SizedBox(height: 15), Text( - 'Emploi du temps du $selectedDayFormatted', + 'Emploi du temps du $selectedDayFormatted2', style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 20, @@ -293,28 +203,41 @@ class __CalendarState extends State { Row( children: [ Padding( - padding: const EdgeInsets.only(top: 8.0, left: 5), + padding: const EdgeInsets.only(top: 15.0, left: 8, bottom: 8), child: ElevatedButton( onPressed: () { _selectDay(DateTime(selectedDay.year, selectedDay.month, selectedDay.day - 1)); }, - child: const Text('<'), + child: const Text( + '<', + style: TextStyle( + fontSize: 25, + color: Colors.black, + ), + ), ) ), const Spacer(), Padding( - padding: const EdgeInsets.only(top: 8.0, left: 5), + padding: const EdgeInsets.only(top: 15.0, right: 8, bottom: 8), child: ElevatedButton( onPressed: () { _selectDay(DateTime(selectedDay.year, selectedDay.month, selectedDay.day + 1)); }, - child: const Text('>'), + child: const Text( + '>', + style: TextStyle( + fontSize: 25, + color: Colors.black, + ), + ), ) ), ], ), + const SizedBox(height: 15), ListView.builder( shrinkWrap: true, physics: const AlwaysScrollableScrollPhysics(), @@ -322,26 +245,52 @@ class __CalendarState extends State { itemBuilder: (context, index) { return Card( elevation: 5, - margin: const EdgeInsets.all(10), + margin: const EdgeInsets.only(left: 15, right: 15, bottom: 15), child: ListTile( - leading: Text(items[index].startTime.format(context)), + leading: Text(items[index].startTime.formatHHmm24()), title: Text(items[index].title), subtitle: Text(items[index].discription), - trailing: items[index].endTime == null ? null : Text(items[index].endTime!.format(context)), + trailing: items[index].endTime == null ? null : Text(items[index].endTime!.formatHHmm24()), onTap: () => showDialog( context: context, builder: (context) => AlertDialog( title: Text(items[index].title), - content: Text(items[index].discription), + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text("Description: ${items[index].discription}"), + Text("Date: ${DateFormat('yyyy-MM-dd').format(items[index].doDate)}"), + Text("Start Time: ${items[index].startTime.formatHHmm24()}"), + Text("End Time: ${items[index].endTime?.formatHHmm24()}"), + Text("Alarm: ${items[index].alarm ? 'Yes' : 'No'}",), + Text("repetation: ${items[index].repetation ? 'Yes' : 'No'}"), + Text("termine: ${items[index].done ? 'Yes' : 'No'}"), + ], + ), actions: [ - // TextButton( - // // child: const Text('Modifier'), - // // onPressed: () => showFormDialog(context, _formKey), - // ), TextButton( child: const Text('ّFermer'), onPressed: () => Navigator.of(context).pop(), ), + TextButton( + child: const Text('Supprimer'), + onPressed: () { + deleteTask(items[index].id!); + Navigator.of(context).pop(); + }, + ), + TextButton( + child: const Text('Modify'), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => createTask(taskData: items[index].toJson(), operation: 'edit',), // Pass the task data + ), + ); + }, + ), ], ), ), @@ -349,12 +298,21 @@ class __CalendarState extends State { ); }, ), - // Padding( - // padding: const EdgeInsets.only(top: 8), - // child: FloatingActionButton( - // onPressed: () => showFormDialog(context, _formKey), - // child: const Icon(Icons.add), - // ), + Padding( + padding: const EdgeInsets.only(top: 8), + child: FloatingActionButton( + onPressed: () { + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (_) => createTask(taskData: {"do_date": selectedDayFormatted},operation: 'creat'), + ), + (Route route) => false, + ); + }, + child: const Icon(Icons.add), + ), + ), // ), diff --git a/lib/Screens/createtask.dart b/lib/Screens/createtask.dart index abe6c73..0b7c2a6 100644 --- a/lib/Screens/createtask.dart +++ b/lib/Screens/createtask.dart @@ -1,25 +1,24 @@ import 'dart:convert'; import 'dart:ffi'; +import 'package:activmind_app/Screens/Calendar.dart'; import 'package:activmind_app/common/gen_text_form_field.dart'; import 'package:http/http.dart' as http; - -import 'package:activmind_app/Screens/tasklist.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; class createTask extends StatefulWidget { - final Map? taskData; + final Map? taskData; final String? operation; - const createTask({Key? key, this.taskData, required this.operation}) : super(key: key); + + const createTask({Key? key, this.taskData, required this.operation}) + : super(key: key); @override State createState() => _createTaskState(); } class _createTaskState extends State { - - final _formKey = GlobalKey(); late final TextEditingController _titleController; @@ -35,45 +34,52 @@ class _createTaskState extends State { late bool repetation; late bool done; + late final TextEditingController _dateIfCancel; + @override void initState() { super.initState(); - _titleController = TextEditingController(text: widget.taskData?['title'] ?? ''); - _descriptionController = TextEditingController(text: widget.taskData?['discription'] ?? ''); - _dateController = TextEditingController(text: widget.taskData?['do_date'] ?? ''); - _timeController = TextEditingController(text: widget.taskData?['start_time'] ?? ''); - _timeendController = TextEditingController(text: widget.taskData?['end_time'] ?? ''); + _titleController = + TextEditingController(text: widget.taskData?['title'] ?? ''); + _descriptionController = + TextEditingController(text: widget.taskData?['discription'] ?? ''); + _dateController = + TextEditingController(text: widget.taskData?['do_date'] ?? ''); + _timeController = + TextEditingController(text: widget.taskData?['start_time'] ?? ''); + _timeendController = + TextEditingController(text: widget.taskData?['end_time'] ?? ''); _selectedDate = DateTime.now(); _selectedTime = TimeOfDay.now(); alarm = widget.taskData?['alarm'] ?? false; repetation = widget.taskData?['repetition'] ?? false; done = widget.taskData?['done'] ?? false; - - operation = widget.operation ?? ''; - taskData = widget.taskData ?? {}; + _dateIfCancel = + TextEditingController(text: widget.taskData?['do_date'] ?? ''); + + operation = widget.operation ?? ''; + taskData = widget.taskData ?? {}; } - String _formatTimeOfDay(TimeOfDay time) { - final now = DateTime.now(); - final dt = DateTime(now.year, now.month, now.day, time.hour, time.minute); - final formatter = DateFormat.Hms(); // 'H' for 24-hour format, 'm' for minutes - return formatter.format(dt); - } - + final now = DateTime.now(); + final dt = DateTime(now.year, now.month, now.day, time.hour, time.minute); + final formatter = + DateFormat.Hms(); // 'H' for 24-hour format, 'm' for minutes + return formatter.format(dt); + } -Future selectOperation(String?operation, Map? taskData) async { - print(operation); - if (operation == 'creat'){ + Future selectOperation( + String? operation, Map? taskData) async { + print(operation); + if (operation == 'creat') { createTask(); - } - else { + } else { updateTask(taskData); } } - Future createTask() async { try { final form = _formKey.currentState; @@ -83,26 +89,24 @@ Future selectOperation(String?operation, Map? taskData) a String strtime = _timeController.text; String endtime = _timeendController.text; - - if(endtime==''){ + if (endtime == '') { endtime = strtime; } Map taskData = { - "title":title, - "discription":description, - "do_date":dodate, - "start_time":strtime, - "end_time":endtime, - "alarm":alarm, - "repetation":repetation, - - }; - if (form!.validate()){ + "title": title, + "discription": description, + "do_date": dodate, + "start_time": strtime, + "end_time": endtime, + "alarm": alarm, + "repetation": repetation, + }; + if (form!.validate()) { SharedPreferences prefs = await SharedPreferences.getInstance(); final token = prefs.getString('token'); - const String apiUrl = 'http://10.0.2.2:8000/tasks/'; - print(apiUrl); + const String apiUrl = 'http://10.0.2.2:8000/tasks/'; + print(apiUrl); final response = await http.post( Uri.parse(apiUrl), @@ -110,21 +114,22 @@ Future selectOperation(String?operation, Map? taskData) a 'Content-Type': 'application/json; charset=UTF-8', 'Authorization': 'Token $token', }, - body: jsonEncode(taskData), + body: jsonEncode(taskData), ); print(jsonEncode(taskData)); print(response.headers); - if (response.statusCode == 201 ) { + if (response.statusCode == 201) { // Task created successfully print('Task updated successfully'); Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute( - builder: (_) => const TaskList(), - ), - (Route route) => false); - + context, + MaterialPageRoute( + builder: (_) => Calendar( + selectedDay: + DateFormat('yyyy-MM-dd').parse(_dateController.text)), + ), + (Route route) => false); } else { // Task creation failed print('Failed to create task. Status code: ${response.statusCode}'); @@ -136,7 +141,6 @@ Future selectOperation(String?operation, Map? taskData) a } } - Future updateTask(task) async { try { final form = _formKey.currentState; @@ -146,26 +150,24 @@ Future selectOperation(String?operation, Map? taskData) a String strtime = _timeController.text; String endtime = _timeendController.text; - - if(endtime==''){ + if (endtime == '') { endtime = strtime; } Map taskData = { - "title":title, - "discription":description, - "do_date":dodate, - "start_time":strtime, - "end_time":endtime, - "alarm":alarm, - "repetation":repetation, - "id":task["id"] - - }; - if (form!.validate()){ + "title": title, + "discription": description, + "do_date": dodate, + "start_time": strtime, + "end_time": endtime, + "alarm": alarm, + "repetation": repetation, + "id": task["id"] + }; + if (form!.validate()) { SharedPreferences prefs = await SharedPreferences.getInstance(); final token = prefs.getString('token'); - final String apiUrl = 'http://10.0.2.2:8000/tasks/${taskData?["id"]}/'; + final String apiUrl = 'http://10.0.2.2:8000/tasks/${taskData?["id"]}/'; print(apiUrl); final response = await http.put( Uri.parse(apiUrl), @@ -180,12 +182,13 @@ Future selectOperation(String?operation, Map? taskData) a // Task updated successfully print('Task updated successfully'); Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute( - builder: (_) => const TaskList(), - ), - (Route route) => false); - + context, + MaterialPageRoute( + builder: (_) => Calendar( + selectedDay: + DateFormat('yyyy-MM-dd').parse(_dateController.text)), + ), + (Route route) => false); } else { // Task update failed print('Failed to update task. Status code: ${response.statusCode}'); @@ -197,60 +200,51 @@ Future selectOperation(String?operation, Map? taskData) a } } - - - @override + @override Widget build(BuildContext context) { - return Builder( - builder: (context) { - return Scaffold( - appBar: AppBar( + return Builder(builder: (context) { + return Scaffold( + appBar: AppBar( backgroundColor: const Color.fromARGB(255, 139, 140, 242), - ), - backgroundColor: const Color.fromARGB(255, 139, 140, 242), - body: SingleChildScrollView( - child: Form( - key: _formKey, - child: SingleChildScrollView( - scrollDirection: Axis.vertical, - child: Container( - color: const Color.fromARGB(255, 139, 140, 242), - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const SizedBox(height: 10.0), - Image.asset( - 'assets/images/logo.png', - height: 50.0, - width: 50.0, - ), - const Text( - "Ajouter une tâche", - style: TextStyle( - fontWeight: FontWeight.bold, - color: Colors.white, - fontSize: 25.0), - ), - const SizedBox(height: 20.0), - GetTextFormField( - controller: _titleController, - icon: Icons.title, - hintName: 'titre*', - inputtype: TextInputType.text, - ), - const SizedBox(height: 5.0), - GetTextFormField( - controller: _descriptionController, - icon: Icons.description, - hintName: 'description *', - - ), - const SizedBox(height: 5.0), - - TextFormField( + ), + backgroundColor: const Color.fromARGB(255, 139, 140, 242), + body: SingleChildScrollView( + child: Form( + key: _formKey, + child: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Container( + color: const Color.fromARGB(255, 139, 140, 242), + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const SizedBox(height: 10.0), + const Text( + "Ajouter une tâche", + style: TextStyle( + fontWeight: FontWeight.bold, + color: Colors.white, + fontSize: 25.0), + ), + const SizedBox(height: 20.0), + GetTextFormField( + controller: _titleController, + icon: Icons.title, + hintName: 'titre*', + inputtype: TextInputType.text, + ), + const SizedBox(height: 10.0), + GetTextFormField( + controller: _descriptionController, + icon: Icons.description, + hintName: 'description *', + ), + const SizedBox(height: 20.0), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20.0), + child: TextFormField( controller: _dateController, - onTap: () async { DateTime? pickedDate = await showDatePicker( context: context, @@ -261,23 +255,25 @@ Future selectOperation(String?operation, Map? taskData) a return Theme( data: ThemeData.light().copyWith( colorScheme: ColorScheme.light( - primary: Color.fromARGB(255, 107, 109, 174), + primary: + Color.fromARGB(255, 107, 109, 174), ), ), child: child!, ); }, ); - if (pickedDate != null && pickedDate != _selectedDate) { + if (pickedDate != null && + pickedDate != _selectedDate) { setState(() { _selectedDate = pickedDate; - _dateController.text = DateFormat('yyyy-MM-dd').format(_selectedDate); + _dateController.text = DateFormat('yyyy-MM-dd') + .format(_selectedDate); }); } }, - readOnly: true, - decoration: InputDecoration( + decoration: const InputDecoration( labelText: 'Select Date', hintText: 'Select Date', prefixIcon: Icon(Icons.calendar_today), @@ -290,25 +286,30 @@ Future selectOperation(String?operation, Map? taskData) a return null; }, ), - - const SizedBox(height: 5.0), - TextFormField( + ), + const SizedBox(height: 20.0), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20.0), + child: TextFormField( controller: _timeController, onTap: () async { TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: _selectedTime, ); - if (pickedTime != null && pickedTime != _selectedTime) { + if (pickedTime != null && + pickedTime != _selectedTime) { setState(() { _selectedTime = pickedTime; // Format the time using 24-hour format - _timeController.text = _formatTimeOfDay(_selectedTime); + _timeController.text = + _formatTimeOfDay(_selectedTime); }); } }, - readOnly: true, // Disable manual editing - decoration: InputDecoration( + readOnly: true, + // Disable manual editing + decoration: const InputDecoration( labelText: 'Heure de début *', hintText: 'Heure de début *', prefixIcon: Icon(Icons.access_time), @@ -321,119 +322,131 @@ Future selectOperation(String?operation, Map? taskData) a return null; }, ), - - - - const SizedBox(height: 5.0), - - TextFormField( + ), + const SizedBox(height: 20.0), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20.0), + child: TextFormField( controller: _timeendController, onTap: () async { TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: _selectedTime, ); - if (pickedTime != null && pickedTime != _selectedTime) { + if (pickedTime != null && + pickedTime != _selectedTime) { setState(() { _selectedTime = pickedTime; // Format the time using 24-hour format - _timeendController.text = _formatTimeOfDay(_selectedTime); + _timeendController.text = + _formatTimeOfDay(_selectedTime); }); } }, readOnly: true, // Disable manual editing - decoration: InputDecoration( + decoration: const InputDecoration( labelText: 'Heure de fin', hintText: 'Heure de fin', prefixIcon: Icon(Icons.access_time), border: OutlineInputBorder(), ), - ), - - - const SizedBox(height: 5.0), - Row( + ), + const SizedBox(height: 5.0), + Container( + padding: const EdgeInsets.all(8), + child: Row( children: [ Checkbox( value: alarm, onChanged: (value) { setState(() { - alarm = value ?? false; // Update the state variable + alarm = value ?? + false; // Update the state variable }); }, ), const Text("Alarm"), ], ), - - Row( + ), + Container( + padding: const EdgeInsets.all(8), + child: Row( children: [ Checkbox( value: repetation, onChanged: (value) { setState(() { - repetation = value ?? false; // Update the state variable + repetation = value ?? + false; // Update the state variable }); }, ), const Text("Repetation"), ], ), - - Row( + ), + Container( + padding: const EdgeInsets.all(8), + child: Row( children: [ Checkbox( value: done, onChanged: (value) { setState(() { - done = value ?? false; // Update the state variable + done = value ?? + false; // Update the state variable }); }, ), const Text("Done"), ], ), - const SizedBox(height: 20.0), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children:[ - ElevatedButton( - style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, backgroundColor: const Color.fromARGB(255, 76, 77, 166), - ), - onPressed:() => selectOperation(operation, taskData), - child: const Text('soumettre'), + ), + const SizedBox(height: 20.0), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, + backgroundColor: + const Color.fromARGB(255, 76, 77, 166), ), - SizedBox(width: 20), - - ElevatedButton( - style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, backgroundColor: const Color.fromARGB(255, 76, 77, 166), - ), - onPressed: () { - - Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute( - builder: (_) => const TaskList(), - ), - (Route route) => false); - - }, - child: const Text('Annoler'), + onPressed: () => + selectOperation(operation, taskData), + child: const Text('soumettre'), + ), + SizedBox(width: 20), + ElevatedButton( + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, + backgroundColor: + const Color.fromARGB(255, 76, 77, 166), ), - ], - ), - ], - ), + onPressed: () { + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (_) => Calendar( + selectedDay: DateFormat('yyyy-MM-dd') + .parse(_dateIfCancel.text)), + ), + (Route route) => false); + }, + child: const Text('Annoler'), + ), + ], + ), + ], ), ), ), ), - ), - ); - } - ); + ), + ), + ); + }); } -} \ No newline at end of file +} diff --git a/lib/Screens/login_form.dart b/lib/Screens/login_form.dart index af35d8d..dce2aaf 100644 --- a/lib/Screens/login_form.dart +++ b/lib/Screens/login_form.dart @@ -57,7 +57,7 @@ class _LoginFormState extends State { // print('Failed to login'); ScaffoldMessenger.of(currentContext).showSnackBar( const SnackBar( - content: Text('Please enter a valid username.'), + content: Text('invalid mail or password'), backgroundColor: Colors.red, ), ); diff --git a/lib/common/task_class.dart b/lib/common/task_class.dart index ca6d4f0..7d14a73 100644 --- a/lib/common/task_class.dart +++ b/lib/common/task_class.dart @@ -1,6 +1,13 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; + +extension TimeOfDayExtension on TimeOfDay { + String formatHHmm() { + return '${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}'; + } +} + class Task { int? id; String title; @@ -13,7 +20,8 @@ class Task { bool done; int userId; - Task({ + +Task({ this.id, required this.title, required this.discription, @@ -26,6 +34,8 @@ class Task { required this.userId, }); + + factory Task.fromJson(Map json) { return Task( id: json['id'], @@ -50,10 +60,10 @@ class Task { 'id': id, 'title': title, 'discription': discription, - 'do_date': doDate.toIso8601String(), - 'start_time': startTime.toString(), - 'end_time': endTime?.toString(), - 'repetition': repetation, + 'do_date': DateFormat('yyyy-MM-dd').format(doDate), + 'start_time': startTime.formatHHmm(), + 'end_time': endTime?.formatHHmm(), + 'repetation': repetation, 'alarm': alarm, 'done': done, 'user': userId, diff --git a/lib/main.dart b/lib/main.dart index 400ebae..43bb119 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,8 @@ import 'package:activmind_app/common/globalvariable.dart'; // import 'Screens/username.dart'; // import 'Screens/inscrire.dart'; // import 'Screens/adresse.dart'; + + Future getToken(BuildContext context) async { SharedPreferences prefs = await SharedPreferences.getInstance(); final token = prefs.getString('token');