Added bottom style sheet for time slot and achievement screen
This commit is contained in:
parent
b0fcb14b0b
commit
8826e0efd3
@ -59,7 +59,6 @@ class _ConsultationTimeSlotScreenState
|
|||||||
int startMins = startTime.hour * 60 + startTime.minute;
|
int startMins = startTime.hour * 60 + startTime.minute;
|
||||||
int endMins = endTime.hour * 60 + endTime.minute;
|
int endMins = endTime.hour * 60 + endTime.minute;
|
||||||
int duration = endMins - startMins;
|
int duration = endMins - startMins;
|
||||||
|
|
||||||
int minimumDuration =
|
int minimumDuration =
|
||||||
int.parse(widget.controller.model.averageDurationMinutes ?? '0');
|
int.parse(widget.controller.model.averageDurationMinutes ?? '0');
|
||||||
if (duration < minimumDuration) {
|
if (duration < minimumDuration) {
|
||||||
@ -94,35 +93,58 @@ class _ConsultationTimeSlotScreenState
|
|||||||
(newEndMins > existingStartMins && newEndMins <= existingEndMins) ||
|
(newEndMins > existingStartMins && newEndMins <= existingEndMins) ||
|
||||||
(newStartMins <= existingStartMins &&
|
(newStartMins <= existingStartMins &&
|
||||||
newEndMins >= existingEndMins)) {
|
newEndMins >= existingEndMins)) {
|
||||||
throw 'This time slot overlaps with existing slot ${slot.startTime} - ${slot.endTime}';
|
throw 'This time slot overlaps with an existing slot';
|
||||||
|
// throw 'This time slot overlaps with existing slot ${slot.startTime} - ${slot.endTime}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addTimeSlot() async {
|
void _addTimeSlot() {
|
||||||
|
TimeOfDay? startTime;
|
||||||
|
TimeOfDay? endTime;
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => StatefulBuilder(
|
||||||
|
builder: (context, setModalState) => Container(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: _buildTimeField(
|
||||||
|
context: context,
|
||||||
|
label: 'Start Time',
|
||||||
|
time: startTime,
|
||||||
|
onSelect: (time) => setModalState(() => startTime = time),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: _buildTimeField(
|
||||||
|
context: context,
|
||||||
|
label: 'End Time',
|
||||||
|
time: endTime,
|
||||||
|
onSelect: (time) => setModalState(() => endTime = time),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (startTime != null && endTime != null) {
|
||||||
try {
|
try {
|
||||||
TimeOfDay? startTime = await showTimePicker(
|
_validateTimeSlot(startTime!, endTime!);
|
||||||
context: context,
|
_validateOverlap(startTime!, endTime!);
|
||||||
initialTime: TimeOfDay.now(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (startTime != null) {
|
|
||||||
TimeOfDay? endTime = await showTimePicker(
|
|
||||||
context: context,
|
|
||||||
initialTime: startTime,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (endTime != null) {
|
|
||||||
_validateTimeSlot(startTime, endTime);
|
|
||||||
_validateOverlap(startTime, endTime);
|
|
||||||
final slot = TimeSlot(
|
final slot = TimeSlot(
|
||||||
startTime: formatTime(startTime),
|
startTime: formatTime(startTime!),
|
||||||
endTime: formatTime(endTime),
|
endTime: formatTime(endTime!),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
widget.controller.addTimeSlot(widget.selectedDay, slot);
|
widget.controller.addTimeSlot(widget.selectedDay, slot);
|
||||||
|
Navigator.pop(context);
|
||||||
|
setState(() {
|
||||||
currentSchedule =
|
currentSchedule =
|
||||||
widget.controller.model.weeklySchedule!.firstWhere(
|
widget.controller.model.weeklySchedule!.firstWhere(
|
||||||
(schedule) => schedule.day == widget.selectedDay,
|
(schedule) => schedule.day == widget.selectedDay,
|
||||||
@ -132,16 +154,65 @@ class _ConsultationTimeSlotScreenState
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
Navigator.pop(context);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
content: Text(e.toString()),
|
content: Text(e.toString()),
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
child: const Text('Add Time Slot'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildTimeField({
|
||||||
|
required BuildContext context,
|
||||||
|
required String label,
|
||||||
|
required TimeOfDay? time,
|
||||||
|
required Function(TimeOfDay) onSelect,
|
||||||
|
}) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(label),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
InkWell(
|
||||||
|
onTap: () async {
|
||||||
|
final selected = await showTimePicker(
|
||||||
|
context: context,
|
||||||
|
initialTime: time ?? TimeOfDay.now(),
|
||||||
|
);
|
||||||
|
if (selected != null) onSelect(selected);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
time != null ? formatTime(time) : 'Select',
|
||||||
|
),
|
||||||
|
const Icon(Icons.access_time),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void _editTimeSlot(TimeSlot currentSlot) async {
|
void _editTimeSlot(TimeSlot currentSlot) async {
|
||||||
try {
|
try {
|
||||||
@ -238,7 +309,9 @@ class _ConsultationTimeSlotScreenState
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Stack(
|
||||||
|
children: [
|
||||||
|
Scaffold(
|
||||||
backgroundColor: Colors.grey[50],
|
backgroundColor: Colors.grey[50],
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
@ -288,8 +361,7 @@ class _ConsultationTimeSlotScreenState
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Container(
|
child: Container(
|
||||||
height:
|
height: MediaQuery.of(context).size.height * 0.2,
|
||||||
MediaQuery.of(context).size.height * 0.2, // Reduced height
|
|
||||||
margin: const EdgeInsets.only(bottom: 250),
|
margin: const EdgeInsets.only(bottom: 250),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
@ -343,7 +415,8 @@ class _ConsultationTimeSlotScreenState
|
|||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final slot = currentSchedule.timeSlots![index];
|
final slot = currentSchedule.timeSlots![index];
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
padding:
|
||||||
|
const EdgeInsets.symmetric(vertical: 8),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: Container(
|
leading: Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
@ -395,8 +468,10 @@ class _ConsultationTimeSlotScreenState
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: Container(
|
),
|
||||||
margin: const EdgeInsets.only(bottom: 270, right: 25),
|
Positioned(
|
||||||
|
bottom: 280,
|
||||||
|
right: 29,
|
||||||
child: FloatingActionButton(
|
child: FloatingActionButton(
|
||||||
onPressed: _addTimeSlot,
|
onPressed: _addTimeSlot,
|
||||||
backgroundColor: const Color(0xFF4FB6D8),
|
backgroundColor: const Color(0xFF4FB6D8),
|
||||||
@ -408,6 +483,7 @@ class _ConsultationTimeSlotScreenState
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,6 +74,60 @@ class _AchievementsScreenState extends State<AchievementsScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _addAchievementBottomSheet() {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
isScrollControlled: true,
|
||||||
|
builder: (context) => Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||||
|
),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'Add Achievement',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
TextFormField(
|
||||||
|
controller: _achievementController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Enter your achievement',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
final achievement = _achievementController.text.trim();
|
||||||
|
if (_validateAchievement(achievement)) {
|
||||||
|
setState(() {
|
||||||
|
achievements.add(achievement);
|
||||||
|
_isEditing = true;
|
||||||
|
});
|
||||||
|
_controller
|
||||||
|
.updateAchievements(List<String>.from(achievements));
|
||||||
|
_achievementController.clear();
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text('Add'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void _removeAchievement(int index) {
|
void _removeAchievement(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
achievements.removeAt(index);
|
achievements.removeAt(index);
|
||||||
@ -138,104 +192,23 @@ class _AchievementsScreenState extends State<AchievementsScreen> {
|
|||||||
arguments: _controller);
|
arguments: _controller);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.arrow_forward)),
|
icon: const Icon(Icons.arrow_forward),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
title: const Text('Achievements'),
|
title: const Text('Achievements'),
|
||||||
),
|
),
|
||||||
body: Form(
|
body: Column(
|
||||||
key: _formKey,
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.all(16.0),
|
padding: EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: Text(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Add Your Achievements',
|
'Add Your Achievements',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Container(
|
|
||||||
margin:
|
|
||||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.blueGrey.withOpacity(0.5),
|
|
||||||
blurRadius: 10,
|
|
||||||
offset: const Offset(0, 2),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12.0),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _achievementController,
|
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: 'Enter your achievement',
|
|
||||||
labelText: 'Achievement',
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.grey[100],
|
|
||||||
suffixIcon: IconButton(
|
|
||||||
icon: const Icon(Icons.add_circle_outline,
|
|
||||||
color: Colors.blue),
|
|
||||||
onPressed: _addAchievement,
|
|
||||||
),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
borderSide:
|
|
||||||
BorderSide(color: Colors.grey.shade300, width: 1),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
borderSide:
|
|
||||||
const BorderSide(color: Colors.blue, width: 1.5),
|
|
||||||
),
|
|
||||||
errorBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
borderSide:
|
|
||||||
const BorderSide(color: Colors.red, width: 1.5),
|
|
||||||
),
|
|
||||||
focusedErrorBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
borderSide:
|
|
||||||
const BorderSide(color: Colors.red, width: 1.5),
|
|
||||||
),
|
|
||||||
helperText: achievements.isEmpty
|
|
||||||
? 'Minimum 3 characters required'
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
validator: (value) {
|
|
||||||
if (achievements.isEmpty) {
|
|
||||||
if (value == null || value.isEmpty) {
|
|
||||||
return 'Please enter an achievement';
|
|
||||||
}
|
|
||||||
if (value.length < 3) {
|
|
||||||
return 'Achievement must be at least 3 characters long';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (value != null &&
|
|
||||||
value.isNotEmpty &&
|
|
||||||
achievements.any((a) =>
|
|
||||||
a.toLowerCase() == value.toLowerCase())) {
|
|
||||||
return 'This achievement has already been added';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
onFieldSubmitted: (_) => _addAchievement(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
@ -262,8 +235,13 @@ class _AchievementsScreenState extends State<AchievementsScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: _addAchievementBottomSheet,
|
||||||
|
backgroundColor: const Color(0xFF4FB6D8),
|
||||||
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user