Skip to content

Commit

Permalink
feat(wip): multiline input in add
Browse files Browse the repository at this point in the history
  • Loading branch information
orl0pl committed Oct 28, 2024
1 parent 8118a30 commit d7e5a8a
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 61 deletions.
6 changes: 6 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"@@locale": "en",
"@about": {},
"@add": {},
"@add_details": {},
"@add_place": {},
"@add_tag": {},
"@all_apps": {},
Expand Down Expand Up @@ -132,6 +133,8 @@
}
},
"@more": {},
"@new_note": {},
"@new_task": {},
"@no_alarm": {},
"@no_internet": {},
"@no_notes": {},
Expand Down Expand Up @@ -268,6 +271,7 @@
},
"about": "About",
"add": "Add",
"add_details": "Add details",
"add_place": "Add place",
"add_tag": "Add tag",
"all_apps": "All apps",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
203 changes: 142 additions & 61 deletions lib/screens/add_redesgin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class AddScreen extends StatefulWidget {
enum EntryType { note, task }

class _AddScreenState extends State<AddScreen> {
ScrollController descriptionFieldScrollController = ScrollController();
FocusNode descriptionFieldFocusNode = FocusNode();
bool descriptionExpanded = false;
String text = "";
List<Tag>? _taskTags;
List<Tag>? _noteTags;
Expand Down Expand Up @@ -130,78 +133,156 @@ class _AddScreenState extends State<AddScreen> {

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);

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)),
],
),
),
])),
]),
)),
);
}
}

0 comments on commit d7e5a8a

Please sign in to comment.