Skip to content

Commit

Permalink
subject management bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
user5522 committed Dec 31, 2024
1 parent ddf4667 commit fefc070
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 90 deletions.
1 change: 1 addition & 0 deletions assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"ok": "OK",
"create": "Create",
"add": "Add",
"edit": "Edit",
"save": "Save",
"proceed": "Proceed",
"delete": "Delete",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"create": "Créer",
"add": "Ajouter",
"save": "Sauvegarder",
"edit": "Éditer",
"proceed": "Continuer",
"delete": "Supprimer",
"cancel": "Annuler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,27 @@ class SubjectManagementBottomSheet extends ConsumerWidget {
final timetables = ref.watch(timetableProvider);
final rotationWeeks = ref.watch(settingsProvider).rotationWeeks;
final customStartTime = ref.watch(settingsProvider).customStartTime;
final subjects = ref.watch(subjectProvider);
final currentSubject = subjects.firstWhere((s) => s.id == subject.id);

Color labelColor =
subject.color.computeLuminance() > .7 ? Colors.black : Colors.white;
Color subLabelsColor = subject.color.computeLuminance() > .7
Color labelColor = currentSubject.color.computeLuminance() > .7
? Colors.black
: Colors.white;
Color subLabelsColor = currentSubject.color.computeLuminance() > .7
? Colors.black.withValues(alpha: .6)
: Colors.white.withValues(alpha: .75);

String label = subject.label;
String? location = subject.location;
Color color = subject.color;
String? note = subject.note;
String label = currentSubject.label;
String? location = currentSubject.location;
Color color = currentSubject.color;
String? note = currentSubject.note;

final bool locationCheck = location != null && location.isNotEmpty;
final bool noteCheck = note != null && note.isNotEmpty;

final inOverlappingSubjectsCheck = () {
for (var couple in overlappingSubjects) {
if (couple.contains(subject)) return true;
if (couple.contains(currentSubject)) return true;
}
return false;
}();
Expand All @@ -59,7 +62,7 @@ class SubjectManagementBottomSheet extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
padding: const EdgeInsets.only(right: 20),
child: ColorIndicator(color: color),
),
Expanded(
Expand All @@ -76,61 +79,59 @@ class SubjectManagementBottomSheet extends ConsumerWidget {
),
],
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 2.5),
),
const Divider(),
const Padding(
padding: EdgeInsets.symmetric(vertical: 2.5),
const Padding(padding: EdgeInsets.symmetric(vertical: 6)),
Row(
children: [
const Padding(padding: EdgeInsets.only(right: 40)),
Expanded(
child: Text(
currentSubject.day.name,
style: TextStyle(
color: subLabelsColor,
fontSize: 17,
),
).tr()),
],
),
const Padding(padding: EdgeInsets.symmetric(vertical: 2.5)),
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
child: Icon(
Icons.schedule_outlined,
size: 19,
const Padding(padding: EdgeInsets.only(right: 40)),
Text(
"${currentSubject.startTime.hour.toString()}:00",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: subLabelsColor,
),
),
Row(
children: [
Text(
"${subject.startTime.hour.toString()}:00",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: subLabelsColor,
),
),
Icon(
Icons.arrow_forward_rounded,
size: 20,
color: subLabelsColor,
),
Text(
"${subject.endTime.hour.toString()}:00",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: subLabelsColor,
),
),
],
Icon(
Icons.arrow_forward_rounded,
size: 20,
color: subLabelsColor,
),
Text(
"${currentSubject.endTime.hour.toString()}:00",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: subLabelsColor,
),
),
],
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 2.5),
),
const Padding(padding: EdgeInsets.symmetric(vertical: 2.5)),
if (locationCheck || noteCheck || rotationWeeks)
const Divider(indent: 40),
if (locationCheck)
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
padding:
const EdgeInsets.only(right: 18, top: 10, bottom: 10),
child: Icon(
Icons.location_on_outlined,
size: 19,
size: 22,
color: subLabelsColor,
),
),
Expand All @@ -141,64 +142,58 @@ class SubjectManagementBottomSheet extends ConsumerWidget {
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: subLabelsColor,
),
),
),
],
),
if (locationCheck && noteCheck)
const Padding(
padding: EdgeInsets.symmetric(vertical: 2.5),
),
if (noteCheck)
if (rotationWeeks && locationCheck) const Divider(indent: 40),
if (rotationWeeks)
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
padding:
const EdgeInsets.only(right: 18, top: 10, bottom: 10),
child: Icon(
Icons.sticky_note_2_outlined,
size: 19,
Icons.screen_rotation_alt_rounded,
size: 22,
color: subLabelsColor,
),
),
Expanded(
child: Text(
note.toString(),
maxLines: 4,
overflow: TextOverflow.ellipsis,
getRotationWeekLabel(currentSubject.rotationWeek),
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: subLabelsColor,
fontSize: 17,
),
),
),
],
),
if (rotationWeeks && noteCheck)
const Padding(
padding: EdgeInsets.symmetric(vertical: 2.5),
),
if (rotationWeeks)
if ((locationCheck || rotationWeeks) && noteCheck)
const Divider(indent: 40),
if (noteCheck)
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
padding:
const EdgeInsets.only(right: 18, top: 10, bottom: 10),
child: Icon(
Icons.screen_rotation_alt_outlined,
size: 19,
Icons.sticky_note_2_outlined,
size: 22,
color: subLabelsColor,
),
),
Expanded(
child: Text(
getRotationWeekLabel(subject.rotationWeek),
note.toString(),
maxLines: 4,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: subLabelsColor,
fontSize: 17,
fontWeight: FontWeight.w500,
color: subLabelsColor,
),
),
),
Expand All @@ -207,17 +202,21 @@ class SubjectManagementBottomSheet extends ConsumerWidget {
],
),
),
if (!inOverlappingSubjectsCheck)
const Divider(indent: 16, endIndent: 16, height: 0),
if (!inOverlappingSubjectsCheck)
ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SubjectScreen(
rowIndex: subject.startTime.hour - customStartTime.hour,
columnIndex: subject.day.index,
rowIndex:
currentSubject.startTime.hour - customStartTime.hour,
columnIndex: currentSubject.day.index,
currentTimetable: ValueNotifier(
timetables.firstWhere((e) => e.name == subject.timetable),
timetables.firstWhere(
(e) => e.name == currentSubject.timetable),
),
),
),
Expand All @@ -226,37 +225,56 @@ class SubjectManagementBottomSheet extends ConsumerWidget {
leading: const Icon(Icons.add_outlined),
title: const Text("add").tr(),
),
const Divider(indent: 16, endIndent: 16, height: 0),
ListTile(
onTap: () {
Navigator.push(
onTap: () async {
final updatedSubject = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SubjectScreen(subject: subject),
builder: (context) => SubjectScreen(subject: currentSubject),
),
);

if (updatedSubject != null) {
await subjectNotifier.updateSubject(updatedSubject);
}
},
horizontalTitleGap: 16,
leading: const Icon(Icons.edit_outlined),
title: const Text("edit").tr(),
),
const Divider(indent: 56, endIndent: 16, height: 0),
ListTile(
onTap: () async {
final navigator = Navigator.of(context);
final messenger = ScaffoldMessenger.of(context);

await subjectNotifier.deleteSubject(subject).then(
(_) {
try {
if (subjects.any((s) => s.id == currentSubject.id)) {
navigator.pop();
messenger.showSnackBar(
SnackBar(
content: const Text('subject_deleted_snackbar').tr(),
),
);
},
);
// TODO: figure something else out for this (Bad state no element)
await Future.delayed(Duration.zero);
await subjectNotifier.deleteSubject(currentSubject).then((_) {
messenger.showSnackBar(
SnackBar(
content: const Text('subject_deleted_snackbar').tr(),
),
);
});
}
} catch (e) {
messenger.showSnackBar(
SnackBar(
content: Text('An error occurred: $e'),
),
);
}
},
horizontalTitleGap: 16,
leading: const Icon(Icons.delete_outlined),
title: const Text("delete").tr(),
)
),
const SizedBox(height: 30),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class SubjectBuilder extends ConsumerWidget {
enableDrag: true,
isDismissible: true,
context: context,
isScrollControlled: true,
builder: (context) {
return Wrap(
children: [
Expand Down

0 comments on commit fefc070

Please sign in to comment.