153 lines
5.2 KiB
Dart
153 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import '../../../controller/home/journal/schedule_controller.dart';
|
|
import '../../widgets/ui/siro_ui.dart';
|
|
|
|
class SchedulePage extends StatelessWidget {
|
|
SchedulePage({super.key});
|
|
final ScheduleController controller = Get.put(ScheduleController());
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SiroPage(
|
|
title: 'My Schedule'.tr,
|
|
padding: SiroUi.pageInsets,
|
|
body: GetBuilder<ScheduleController>(builder: (sc) {
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SiroHeroHeader(
|
|
label: 'Weekly Plan'.tr,
|
|
value: '${sc.totalWeeklyHours.toStringAsFixed(1)}h',
|
|
caption: '${sc.activeDays} ${'Days'.tr}',
|
|
icon: Icons.calendar_today_rounded,
|
|
trailing: Container(
|
|
padding: const EdgeInsets.all(14),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withValues(alpha: 0.15),
|
|
borderRadius: BorderRadius.circular(14),
|
|
),
|
|
child: const Icon(Icons.calendar_month_rounded,
|
|
color: Colors.white, size: 26),
|
|
),
|
|
),
|
|
SiroSectionTitle('Work Days'.tr),
|
|
...sc.schedule.map((slot) => _buildDayCard(context, slot, sc)),
|
|
const SizedBox(height: 16),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
|
|
Widget _buildDayCard(
|
|
BuildContext context, WorkSlot slot, ScheduleController sc) {
|
|
final isAr = Get.locale?.languageCode == 'ar';
|
|
final accent = SiroUi.interactive(context);
|
|
final off = SiroUi.subtle(context);
|
|
|
|
return SiroCard(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
margin: const EdgeInsets.only(bottom: 10),
|
|
accent: slot.isActive ? accent : null,
|
|
child: Row(children: [
|
|
// Toggle
|
|
GestureDetector(
|
|
onTap: () => sc.toggleDay(slot.dayOfWeek),
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 200),
|
|
width: 42,
|
|
height: 42,
|
|
decoration: BoxDecoration(
|
|
color: slot.isActive
|
|
? accent.withValues(alpha: 0.12)
|
|
: off.withValues(alpha: 0.10),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
isAr ? slot.dayNameAr.substring(0, 2) : slot.dayName,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
color: slot.isActive ? accent : off,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
// Day name
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
isAr ? slot.dayNameAr : slot.dayName.tr,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
color: slot.isActive ? null : off,
|
|
),
|
|
),
|
|
Text(
|
|
slot.isActive ? slot.timeRange : 'Day Off'.tr,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
fontSize: 12,
|
|
fontStyle:
|
|
slot.isActive ? FontStyle.normal : FontStyle.italic,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// Time pickers
|
|
if (slot.isActive) ...[
|
|
_timePicker(context, slot.startTime,
|
|
(t) => sc.updateStartTime(slot.dayOfWeek, t)),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 3),
|
|
child: Text('-', style: TextStyle(color: off)),
|
|
),
|
|
_timePicker(context, slot.endTime,
|
|
(t) => sc.updateEndTime(slot.dayOfWeek, t)),
|
|
],
|
|
// Toggle switch
|
|
Switch(
|
|
value: slot.isActive,
|
|
onChanged: (_) => sc.toggleDay(slot.dayOfWeek),
|
|
activeThumbColor: accent,
|
|
),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _timePicker(
|
|
BuildContext context, TimeOfDay time, Function(TimeOfDay) onChanged) {
|
|
return GestureDetector(
|
|
onTap: () async {
|
|
final picked =
|
|
await showTimePicker(context: context, initialTime: time);
|
|
if (picked != null) onChanged(picked);
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
|
|
decoration: BoxDecoration(
|
|
color: SiroUi.interactive(context).withValues(alpha: 0.10),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Text(
|
|
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}',
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w700,
|
|
color: SiroUi.interactive(context),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|