diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 538d7a0..da08f6a 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -2,6 +2,7 @@ "@@locale": "en", "@about": {}, "@add": {}, + "@add_details": {}, "@add_place": {}, "@add_tag": {}, "@all_apps": {}, @@ -132,6 +133,8 @@ } }, "@more": {}, + "@new_note": {}, + "@new_task": {}, "@no_alarm": {}, "@no_internet": {}, "@no_notes": {}, @@ -268,6 +271,7 @@ }, "about": "About", "add": "Add", + "add_details": "Add details", "add_place": "Add place", "add_tag": "Add tag", "all_apps": "All apps", @@ -323,6 +327,8 @@ "meters": "{num, plural, other{meters} zero{meters} one{meter} two{meters} few{meters} many{meters}}", "months_num_plural": "{monthsNum, plural, =0{months} =1{month} =2{months} few{months} many{months} other{months}}", "more": "More", + "new_note": "New note", + "new_task": "New task", "no_alarm": "No alarm", "no_internet": "No internet", "no_notes": "No notes", diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index 67e6380..6955aee 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -2,6 +2,7 @@ "@@locale": "pl", "about": "O aplikacji", "add": "Dodaj", + "add_details": "Dodaj szczegóły", "add_place": "Dodaj miejsce", "add_tag": "Dodaj tag", "all_apps": "Wszystkie aplikacje", @@ -57,6 +58,8 @@ "meters": "{num, plural, =0{metrów} =1{metr} =2{metry} few{metry} many{metrów} other{metrów}}", "months_num_plural": "{monthsNum, plural, =0{miesiący} =1{miesiąc} =2{miesiące} few{miesiące} many{miesiące} other{miesiące}}", "more": "Więcej", + "new_note": "Nowa notatka", + "new_task": "Nowe zadanie", "no_alarm": "Brak alarmów", "no_internet": "Brak internetu", "no_notes": "Brak notatek", diff --git a/lib/screens/add_redesgin.dart b/lib/screens/add_redesgin.dart index 6f80392..4d32275 100644 --- a/lib/screens/add_redesgin.dart +++ b/lib/screens/add_redesgin.dart @@ -24,6 +24,9 @@ class AddScreen extends StatefulWidget { enum EntryType { note, task } class _AddScreenState extends State { + ScrollController descriptionFieldScrollController = ScrollController(); + FocusNode descriptionFieldFocusNode = FocusNode(); + bool descriptionExpanded = false; String text = ""; List? _taskTags; List? _noteTags; @@ -130,6 +133,41 @@ class _AddScreenState extends State { bool get canSubmit => false; //text.isNotEmpty; + bool get descriptionEmpty { + if (text.split("\n").length <= 1) { + return true; + } else if (text.split("\n")[1].isEmpty) { + return true; + } else { + return false; + } + } + + String? get descriptionText => descriptionEmpty ? null : text.split("\n")[1]; + + set descriptionText(String? value) { + if (value == null) { + text = ""; + } else { + text = "$text\n$value"; + } + } + + void handleTextChange(String value) { + setState(() { + text = value; + noteDraft.text = value.trim(); + taskDraft.text = value.trim(); + }); + } + + void handleDescriptionChange(String value) { + setState(() { + descriptionText = value; + text = "$text\n$value"; + }); + } + @override Widget build(BuildContext context) { AppLocalizations l = AppLocalizations.of(context); @@ -137,71 +175,114 @@ class _AddScreenState extends State { return Scaffold( appBar: AppBar(title: Text(l.add)), body: SafeArea( - child: Column(mainAxisSize: MainAxisSize.min, children: [ - const Spacer(), - Container( - padding: const EdgeInsets.all(16.0), - child: TextField( - autofocus: true, - decoration: InputDecoration( - hintText: l.content_to_add, - border: InputBorder.none, + child: Expanded( + child: Column(mainAxisSize: MainAxisSize.min, children: [ + // const Spacer(), + Container( + padding: const EdgeInsets.symmetric(horizontal: 16.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextFormField( + autofocus: true, + decoration: InputDecoration( + hintText: + entryType == EntryType.task ? l.new_task : l.new_note, + border: InputBorder.none, + ), + onChanged: (value) { + setState(() { + text = value.trim(); + noteDraft.text = value.trim(); + taskDraft.text = value.trim(); + }); + }, + style: Theme.of(context).textTheme.headlineSmall, + maxLines: 1, + ), + ConstrainedBox( + constraints: BoxConstraints( + maxHeight: descriptionExpanded ? double.infinity : 120.0), + child: TextFormField( + scrollController: descriptionFieldScrollController, + minLines: 1, + maxLines: 120, + initialValue: descriptionText, + focusNode: descriptionFieldFocusNode, + onTapOutside: (event) { + descriptionFieldFocusNode.unfocus(); + }, + decoration: InputDecoration( + hintText: l.add_details, + border: InputBorder.none, + suffixIcon: IconButton.filled( + icon: Icon(MdiIcons.arrowExpandAll), + isSelected: descriptionExpanded, + onPressed: () { + setState(() { + descriptionExpanded = !descriptionExpanded; + }); + }), + ), + onChanged: handleDescriptionChange, + style: Theme.of(context).textTheme.bodyMedium, + ), + ) + ], ), - onChanged: (value) { - setState(() { - text = value.trim(); - noteDraft.text = value.trim(); - taskDraft.text = value.trim(); - }); - }, - style: Theme.of(context).textTheme.headlineSmall, - ), - ), - if (entryType == EntryType.task) - TaskAdding( - updateDataForTask: updateDataForTask, - updateTagsForTask: updateTagsForTask, - selectedTagsIds: selectedTaskTagsIds, - taskDraft: taskDraft, - places: places, - tags: _taskTags, ), - Container( - padding: const EdgeInsets.all(16.0), - margin: const EdgeInsets.only(top: 16), - decoration: BoxDecoration( - border: Border( - top: BorderSide( - color: Theme.of(context).colorScheme.outlineVariant), + if (entryType == EntryType.task) + Expanded( + child: AnimatedFractionallySizedBox( + duration: Durations.medium1, + heightFactor: descriptionExpanded ? 0 : 1, + child: TaskAdding( + updateDataForTask: updateDataForTask, + updateTagsForTask: updateTagsForTask, + selectedTagsIds: selectedTaskTagsIds, + taskDraft: taskDraft, + places: places, + tags: _taskTags, + ), + ), + ), + Container( + padding: const EdgeInsets.all(16.0), + margin: const EdgeInsets.only(top: 16), + decoration: BoxDecoration( + border: Border( + top: BorderSide( + color: Theme.of(context).colorScheme.outlineVariant), + ), + ), + child: Row( + children: [ + const SizedBox(width: 8), + SegmentedButton( + showSelectedIcon: false, + multiSelectionEnabled: false, + segments: const [ + ButtonSegment( + value: EntryType.note, + icon: Icon(MdiIcons.noteOutline)), + ButtonSegment( + value: EntryType.task, + icon: Icon(MdiIcons.checkboxMarkedCircleOutline)), + ], + selected: {entryType}, + onSelectionChanged: (value) { + setState(() { + entryType = value.last; + }); + }), + const Spacer(), + FilledButton.icon( + onPressed: canSubmit ? submit : null, label: Text(l.save)), + ], ), ), - child: Row( - children: [ - const SizedBox(width: 8), - SegmentedButton( - showSelectedIcon: false, - multiSelectionEnabled: false, - segments: const [ - ButtonSegment( - value: EntryType.note, - icon: Icon(MdiIcons.noteOutline)), - ButtonSegment( - value: EntryType.task, - icon: Icon(MdiIcons.checkboxMarkedCircleOutline)), - ], - selected: {entryType}, - onSelectionChanged: (value) { - setState(() { - entryType = value.last; - }); - }), - const Spacer(), - FilledButton.icon( - onPressed: canSubmit ? submit : null, label: Text(l.save)), - ], - ), - ), - ])), + ]), + )), ); } }