Skip to content

Commit

Permalink
Add: Choosing the already selected due date (via lesson chip) with th…
Browse files Browse the repository at this point in the history
…e date selection dialog will change the selection from chip to manual date.
  • Loading branch information
Jonas-Sander committed Dec 6, 2023
1 parent 751f76f commit 5b1cc4b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
13 changes: 9 additions & 4 deletions app/lib/homework/homework_dialog/homework_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,20 @@ class _TodoUntilPicker extends StatelessWidget {
color: state.dueDate.error != null ? Colors.red : null,
),
child: DatePicker(
key: HwDialogKeys.todoUntilTile,
padding: showLessonChips
? const EdgeInsets.fromLTRB(12, 12, 12, 5)
: const EdgeInsets.all(12),
selectedDate: state.dueDate.$1?.toDateTime,
// If a user chooses a date that was already selected by using a
// due date selection chip, we want [selectDate] to be called
// anyways so we can change the selection to a manual due date
// selection (chip will be deselected).
ignoreSameDateSelection: false,
selectDate: (newDate) {
bloc.add(DueDateChanged(
DueDateSelection.date(Date.fromDateTime(newDate))));
},
key: HwDialogKeys.todoUntilTile,
padding: showLessonChips
? const EdgeInsets.fromLTRB(12, 12, 12, 5)
: const EdgeInsets.all(12),
),
),
if (showLessonChips)
Expand Down
23 changes: 15 additions & 8 deletions lib/sharezone_widgets/lib/src/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ class LoadingCircle extends StatelessWidget {
}

class DatePicker extends StatelessWidget {
const DatePicker(
{Key? key,
this.labelText,
this.selectedDate,
this.selectDate,
this.padding})
: super(key: key);
const DatePicker({
Key? key,
this.labelText,
this.selectedDate,
this.selectDate,
this.padding,
this.ignoreSameDateSelection = true,
}) : super(key: key);

final String? labelText;
final DateTime? selectedDate;
final ValueChanged<DateTime>? selectDate;
final EdgeInsets? padding;

/// Whether to call [selectDate] if the chosen date equals [selectedDate].
final bool ignoreSameDateSelection;

Future<void> _selectDate(BuildContext context) async {
FocusManager.instance.primaryFocus?.unfocus();
final DateTime tomorrow =
Expand All @@ -70,7 +74,10 @@ class DatePicker extends StatelessWidget {
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101),
);
if (picked != null && picked != selectedDate) selectDate!(picked);

if (picked == null) return;
if (ignoreSameDateSelection && picked == selectedDate) return;
selectDate!(picked);
}

@override
Expand Down

0 comments on commit 5b1cc4b

Please sign in to comment.