Skip to content

Commit

Permalink
add an option to update notification date and time
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexForget committed Jan 18, 2024
1 parent 53169d6 commit 9d55b88
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 40 deletions.
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"noteNoteRegister": "No notes have been recorded yet",
"addReminder": "Add a reminder",
"notificationWillBeSent": "A notification will be sent on",
"reminder": "Reminder"
"reminder": "Reminder",
"updateReminder": "Modify reminder"
}
5 changes: 3 additions & 2 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"record": "Enregistrer",
"delete": "Supprimer",
"noteNoteRegister": "Aucunte note n'a encore été enregistré",
"addReminder": "Ajouter une rappel",
"addReminder": "Ajouter un rappel",
"notificationWillBeSent": "Une notification sera envoyé le",
"reminder": "Rappel"
"reminder": "Rappel",
"updateReminder": "Modifier le rappel"
}
38 changes: 14 additions & 24 deletions lib/src/features/notes/presentation/screen/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,20 @@ class _HomePageState extends State<HomePage> {
}
return true;
},
child: Column(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.only(top: Sizes.p4),
child: ReorderableListView.builder(
onReorder: (oldIndex, newIndex) {
context.read<NoteListBloc>().add(ReorderedList(
oldIndex: oldIndex, newIndex: newIndex));
},
itemCount: notes.length,
itemBuilder: (context, index) {
final note = notes[index];
return BuildNoteTile(
context: context,
note: note,
key: ObjectKey(
note), //Key(notes[index].id.toString()),
);
},
),
),
),
],
child: ReorderableListView.builder(
onReorder: (oldIndex, newIndex) {
context.read<NoteListBloc>().add(
ReorderedList(oldIndex: oldIndex, newIndex: newIndex));
},
itemCount: notes.length,
itemBuilder: (context, index) {
final note = notes[index];
return BuildNoteTile(
context: context,
note: note,
key: ObjectKey(note), //Key(notes[index].id.toString()),
);
},
),
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BuildNoteTile extends StatelessWidget {
final String deviceLocal = Platform.localeName;
return Padding(
padding: const EdgeInsets.only(
left: Sizes.p12, right: Sizes.p12, top: Sizes.p4, bottom: Sizes.p4),
left: Sizes.p12, right: Sizes.p12, top: Sizes.p8),
child: Container(
padding: const EdgeInsets.all(0),
decoration: BoxDecoration(
Expand Down
119 changes: 107 additions & 12 deletions lib/src/features/notes/presentation/widget/edit_note_alert_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,105 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';
import 'package:omni_datetime_picker/omni_datetime_picker.dart';
import 'package:to_do_app/src/features/notes/bloc/note_list_bloc.dart';
import 'package:to_do_app/src/features/notes/models/note_model.dart';
import 'package:to_do_app/src/helpers/app_sizes.dart';
import 'package:to_do_app/src/localisation/string_hardcoded.dart';

class EditNoteAlertDialog extends StatelessWidget {
class EditNoteAlertDialog extends StatefulWidget {
final TextEditingController descriptionController;
final NoteModel note;
const EditNoteAlertDialog({
super.key,
required this.descriptionController,
required this.note,
});

final TextEditingController descriptionController;
final NoteModel note;
@override
State<EditNoteAlertDialog> createState() => _EditNoteAlertDialogState();
}

class _EditNoteAlertDialogState extends State<EditNoteAlertDialog> {
final String deviceLocal = Platform.localeName;
bool noteAlreadyHasNotification = false;
String formattedDate = '';
DateTime? notificationDateTime;

@override
void initState() {
noteAlreadyHasNotification =
widget.note.notification == null ? false : true;
if (widget.note.notification != null) {
formattedDate = DateFormat.MMMd(deviceLocal)
.add_Hm()
.format(widget.note.notification!);
notificationDateTime = widget.note.notification;
}
super.initState();
}

@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.modifyNote),
content: TextField(
textCapitalization: TextCapitalization.sentences,
controller: descriptionController,
minLines: 1,
maxLines: 5,
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
textCapitalization: TextCapitalization.sentences,
controller: widget.descriptionController,
minLines: 1,
maxLines: 5,
),
Padding(
padding: const EdgeInsets.only(top: Sizes.p20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.background,
),
onPressed: () async {
updateNotification();
},
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: Sizes.p12),
child: Text(
noteAlreadyHasNotification
? AppLocalizations.of(context)!.updateReminder
: AppLocalizations.of(context)!.addReminder,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
),
),
),
Icon(
Icons.calendar_today,
color: Theme.of(context).colorScheme.primary,
),
],
),
)
],
),
),
Padding(
padding: const EdgeInsets.only(top: Sizes.p16, bottom: Sizes.p16),
child: notificationDateTime != null
? Text(
textAlign: TextAlign.center,
'${AppLocalizations.of(context)!.notificationWillBeSent} $formattedDate')
: null,
),
],
),
),
actions: <Widget>[
TextButton(
Expand All @@ -33,11 +110,15 @@ class EditNoteAlertDialog extends StatelessWidget {
),
TextButton(
onPressed: () {
if (descriptionController.text.isNotEmpty) {
note.description = descriptionController.text.trim();
context.read<NoteListBloc>().add(UpdateNote(note: note));
if (widget.descriptionController.text.isNotEmpty) {
widget.note.description =
widget.descriptionController.text.trim();
if (notificationDateTime != null) {
widget.note.notification = notificationDateTime;
}
context.read<NoteListBloc>().add(UpdateNote(note: widget.note));
Navigator.pop(context);
descriptionController.text = '';
widget.descriptionController.text = '';
}
},
child: Text(
Expand All @@ -47,4 +128,18 @@ class EditNoteAlertDialog extends StatelessWidget {
],
);
}

void updateNotification() async {
notificationDateTime = await showOmniDateTimePicker(
context: context,
firstDate: DateTime.now(),
is24HourMode: true,
);
if (notificationDateTime != null) {
setState(() {
formattedDate =
DateFormat.MMMd(deviceLocal).add_Hm().format(notificationDateTime!);
});
}
}
}

0 comments on commit 9d55b88

Please sign in to comment.