Skip to content

Commit

Permalink
feat: update bottom sheets to handle nested navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
DasProffi committed Sep 18, 2024
1 parent a075918 commit fe095c1
Show file tree
Hide file tree
Showing 23 changed files with 946 additions and 624 deletions.
30 changes: 15 additions & 15 deletions apps/tasks/lib/components/assignee_select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:helpwave_localization/localization.dart';
import 'package:helpwave_service/user.dart';
import 'package:helpwave_theme/constants.dart';
import 'package:helpwave_widget/bottom_sheets.dart';
import 'package:helpwave_widget/content_selection.dart';

Expand All @@ -22,31 +21,32 @@ class AssigneeSelectBottomSheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BottomSheetBase(
titleText: context.localization!.assignee,
header: BottomSheetHeader(
titleText: context.localization!.assignee,
),
onClosing: () => {},
builder: (context) => Padding(
padding: const EdgeInsets.symmetric(vertical: paddingMedium),
child: Column(
builder: (context) => Column(
children: [
TextButton(
child: Text(context.localization!.remove),
onPressed: () => onChanged(null),
),
const SizedBox(height: 10),
ListSelect(
items: users,
onSelect: onChanged,
builder: (context, user, select) => ListTile(
onTap: select,
leading: CircleAvatar(
foregroundColor: Colors.blue, backgroundImage: NetworkImage(user.profileUrl.toString())),
title: Text(user.nickName,
style: TextStyle(decoration: user.id == selectedId ? TextDecoration.underline : null)),
SingleChildScrollView(
child: ListSelect(
items: users,
onSelect: onChanged,
builder: (context, user, select) => ListTile(
onTap: select,
leading: CircleAvatar(
foregroundColor: Colors.blue, backgroundImage: NetworkImage(user.profileUrl.toString())),
title: Text(user.nickName,
style: TextStyle(decoration: user.id == selectedId ? TextDecoration.underline : null)),
),
),
),
],
),
),
);
}
}
270 changes: 137 additions & 133 deletions apps/tasks/lib/components/patient_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,31 @@ class _PatientBottomSheetState extends State<PatientBottomSheet> {
),
],
child: BottomSheetBase(
title: Consumer<PatientController>(builder: (context, patientController, _) {
if (patientController.state == LoadingState.loaded || patientController.isCreating) {
return ClickableTextEdit(
initialValue: patientController.patient.name,
onUpdated: patientController.changeName,
textAlign: TextAlign.center,
textStyle: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
fontSize: iconSizeTiny,
fontFamily: "SpaceGrotesk",
overflow: TextOverflow.ellipsis,
),
);
} else {
return const PulsingContainer(width: 30);
}
}),
header: BottomSheetHeader(
title: Consumer<PatientController>(builder: (context, patientController, _) {
if (patientController.state == LoadingState.loaded || patientController.isCreating) {
return ClickableTextEdit(
initialValue: patientController.patient.name,
onUpdated: patientController.changeName,
textAlign: TextAlign.center,
textStyle: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
fontSize: iconSizeTiny,
fontFamily: "SpaceGrotesk",
overflow: TextOverflow.ellipsis,
),
);
} else {
return const PulsingContainer(width: 30);
}
}),
),
onClosing: () {
// TODO handle this
},
bottomWidget: Padding(
padding: const EdgeInsets.only(top: paddingMedium),
padding: const EdgeInsets.only(top: paddingSmall),
child: Consumer<PatientController>(builder: (context, patientController, _) {
return LoadingAndErrorWidget(
state: patientController.state,
Expand Down Expand Up @@ -145,129 +147,131 @@ class _PatientBottomSheetState extends State<PatientBottomSheet> {
));
}),
),
builder: (BuildContext context) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Consumer<PatientController>(builder: (context, patientController, _) {
return LoadingFutureBuilder(
data: loadRoomsWithBeds(patientController.patient.id),
// TODO use a better loading widget
loadingWidget: const SizedBox(),
thenWidgetBuilder: (context, beds) {
if (beds.isEmpty) {
return Text(
context.localization!.noFreeBeds,
style: TextStyle(color: Theme.of(context).disabledColor, fontWeight: FontWeight.bold),
);
}
return DropdownButtonHideUnderline(
child: DropdownButton<RoomWithBedFlat>(
iconEnabledColor: Theme.of(context).colorScheme.secondary.withOpacity(0.6),
padding: EdgeInsets.zero,
isDense: true,
hint: Text(
context.localization!.assignBed,
style: TextStyle(color: Theme.of(context).colorScheme.secondary.withOpacity(0.6)),
builder: (BuildContext context) => SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Consumer<PatientController>(builder: (context, patientController, _) {
return LoadingFutureBuilder(
data: loadRoomsWithBeds(patientController.patient.id),
// TODO use a better loading widget
loadingWidget: const SizedBox(),
thenWidgetBuilder: (context, beds) {
if (beds.isEmpty) {
return Text(
context.localization!.noFreeBeds,
style: TextStyle(color: Theme.of(context).disabledColor, fontWeight: FontWeight.bold),
);
}
return DropdownButtonHideUnderline(
child: DropdownButton<RoomWithBedFlat>(
iconEnabledColor: Theme.of(context).colorScheme.secondary.withOpacity(0.6),
padding: EdgeInsets.zero,
isDense: true,
hint: Text(
context.localization!.assignBed,
style: TextStyle(color: Theme.of(context).colorScheme.secondary.withOpacity(0.6)),
),
value: beds.where((beds) => beds.bed.id == patientController.patient.bed?.id).firstOrNull,
items: beds
.map((roomWithBed) => DropdownMenuItem(
value: roomWithBed,
child: Text(
"${roomWithBed.room.name} - ${roomWithBed.bed.name}",
style: TextStyle(color: Theme.of(context).colorScheme.primary.withOpacity(0.6)),
),
))
.toList(),
onChanged: (RoomWithBedFlat? value) {
// TODO later unassign here
if (value == null) {
return;
}
patientController.assignToBed(value.room, value.bed);
},
),
value: beds.where((beds) => beds.bed.id == patientController.patient.bed?.id).firstOrNull,
items: beds
.map((roomWithBed) => DropdownMenuItem(
value: roomWithBed,
child: Text(
"${roomWithBed.room.name} - ${roomWithBed.bed.name}",
style: TextStyle(color: Theme.of(context).colorScheme.primary.withOpacity(0.6)),
),
))
.toList(),
onChanged: (RoomWithBedFlat? value) {
// TODO later unassign here
if (value == null) {
return;
}
patientController.assignToBed(value.room, value.bed);
},
),
);
},
);
}),
),
Text(
context.localization!.notes,
style: const TextStyle(fontSize: fontSizeBig, fontWeight: FontWeight.bold),
),
const SizedBox(height: distanceSmall),
Consumer<PatientController>(
builder: (context, patientController, _) =>
patientController.state == LoadingState.loaded || patientController.isCreating
? TextFormFieldWithTimer(
initialValue: patientController.patient.notes,
maxLines: 6,
onUpdate: patientController.changeNotes,
)
: TextFormField(maxLines: 6),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: paddingMedium),
child: Consumer<PatientController>(builder: (context, patientController, _) {
Patient patient = patientController.patient;
return AddList(
maxHeight: width * 0.5,
items: [
...patient.unscheduledTasks,
...patient.inProgressTasks,
...patient.doneTasks,
],
itemBuilder: (_, index, taskList) {
if (index == 0) {
return TaskExpansionTile(
tasks: patient.unscheduledTasks
.map((task) => TaskWithPatient.fromTaskAndPatient(
task: task,
patient: patient,
))
.toList(),
title: context.localization!.upcoming,
color: upcomingColor,
);
}
if (index == 2) {
},
);
}),
),
Text(
context.localization!.notes,
style: const TextStyle(fontSize: fontSizeBig, fontWeight: FontWeight.bold),
),
const SizedBox(height: distanceSmall),
Consumer<PatientController>(
builder: (context, patientController, _) =>
patientController.state == LoadingState.loaded || patientController.isCreating
? TextFormFieldWithTimer(
initialValue: patientController.patient.notes,
maxLines: 6,
onUpdate: patientController.changeNotes,
)
: TextFormField(maxLines: 6),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: paddingMedium),
child: Consumer<PatientController>(builder: (context, patientController, _) {
Patient patient = patientController.patient;
return AddList(
maxHeight: width * 0.5,
items: [
...patient.unscheduledTasks,
...patient.inProgressTasks,
...patient.doneTasks,
],
itemBuilder: (_, index, taskList) {
if (index == 0) {
return TaskExpansionTile(
tasks: patient.unscheduledTasks
.map((task) => TaskWithPatient.fromTaskAndPatient(
task: task,
patient: patient,
))
.toList(),
title: context.localization!.upcoming,
color: upcomingColor,
);
}
if (index == 2) {
return TaskExpansionTile(
tasks: patient.doneTasks
.map((task) => TaskWithPatient.fromTaskAndPatient(
task: task,
patient: patient,
))
.toList(),
title: context.localization!.inProgress,
color: inProgressColor,
);
}
return TaskExpansionTile(
tasks: patient.doneTasks
tasks: patient.inProgressTasks
.map((task) => TaskWithPatient.fromTaskAndPatient(
task: task,
patient: patient,
))
.toList(),
title: context.localization!.inProgress,
color: inProgressColor,
title: context.localization!.done,
color: doneColor,
);
}
return TaskExpansionTile(
tasks: patient.inProgressTasks
.map((task) => TaskWithPatient.fromTaskAndPatient(
task: task,
patient: patient,
))
.toList(),
title: context.localization!.done,
color: doneColor,
);
},
title: Text(
context.localization!.tasks,
style: const TextStyle(fontSize: fontSizeBig, fontWeight: FontWeight.bold),
),
// TODO use return value to add it to task list or force a refetch
onAdd: () => context.pushModal(
context: context,
builder: (context) => TaskBottomSheet(task: Task.empty(patient.id), patient: patient),
),
);
}),
),
],
},
title: Text(
context.localization!.tasks,
style: const TextStyle(fontSize: fontSizeBig, fontWeight: FontWeight.bold),
),
// TODO use return value to add it to task list or force a refetch
onAdd: () => context.pushModal(
context: context,
builder: (context) => TaskBottomSheet(task: Task.empty(patient.id), patient: patient),
),
);
}),
),
],
),
),
),
);
Expand Down
Loading

0 comments on commit fe095c1

Please sign in to comment.