added pages to project
This commit is contained in:
+207
-154
@@ -2,13 +2,15 @@ import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../models/lesson.dart';
|
||||
import '../models/school.dart';
|
||||
import '../services/vanguard_api.dart';
|
||||
import '../services/lessons_api.dart';
|
||||
import 'select_school_page.dart';
|
||||
import 'home_page.dart';
|
||||
import 'meditation_page.dart';
|
||||
import '../widgets/app_drawer.dart';
|
||||
import '../widgets/app_bottom_nav.dart';
|
||||
import '../widgets/yogibook_background.dart';
|
||||
import 'reschedule_page.dart';
|
||||
import 'orders_page.dart';
|
||||
|
||||
class LessonsPage extends StatefulWidget {
|
||||
final String token;
|
||||
@@ -31,10 +33,8 @@ class _LessonsPageState extends State<LessonsPage> {
|
||||
String error = '';
|
||||
|
||||
String currentMonth = DateFormat('yyyy-MM').format(DateTime.now());
|
||||
String? prevMonth;
|
||||
String? nextMonth;
|
||||
|
||||
String? schoolAddress;
|
||||
LessonsSummary? summary;
|
||||
List<Lesson> lessons = [];
|
||||
|
||||
int bottomIndex = 1;
|
||||
@@ -52,22 +52,15 @@ class _LessonsPageState extends State<LessonsPage> {
|
||||
});
|
||||
|
||||
try {
|
||||
final data = await VanguardApi.getMyLessons(
|
||||
final data = await LessonsApi.fetchMyLessons(
|
||||
token: widget.token,
|
||||
schoolId: widget.school.id,
|
||||
month: currentMonth,
|
||||
);
|
||||
|
||||
prevMonth = data['prev_month']?.toString();
|
||||
nextMonth = data['next_month']?.toString();
|
||||
schoolAddress = (data['school'] as Map<String, dynamic>?)?['address_full']
|
||||
?.toString();
|
||||
|
||||
final list = (data['lessons'] as List<dynamic>? ?? [])
|
||||
.map((e) => Lesson.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
setState(() => lessons = list);
|
||||
setState(() {
|
||||
summary = data.summary;
|
||||
lessons = data.lessons;
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() => error = 'Errore: $e');
|
||||
} finally {
|
||||
@@ -75,6 +68,23 @@ class _LessonsPageState extends State<LessonsPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// Navigazione mesi calcolata lato client (l'API non restituisce prev/next).
|
||||
String _shiftMonth(String yyyyMm, int delta) {
|
||||
final dt = DateFormat('yyyy-MM').parse(yyyyMm);
|
||||
final shifted = DateTime(dt.year, dt.month + delta, 1);
|
||||
return DateFormat('yyyy-MM').format(shifted);
|
||||
}
|
||||
|
||||
void _goPrevMonth() {
|
||||
setState(() => currentMonth = _shiftMonth(currentMonth, -1));
|
||||
_load();
|
||||
}
|
||||
|
||||
void _goNextMonth() {
|
||||
setState(() => currentMonth = _shiftMonth(currentMonth, 1));
|
||||
_load();
|
||||
}
|
||||
|
||||
String _monthLabel(String yyyyMm) {
|
||||
final dt = DateFormat('yyyy-MM').parse(yyyyMm);
|
||||
return DateFormat('MMMM yyyy', 'it_IT').format(dt);
|
||||
@@ -194,41 +204,58 @@ class _LessonsPageState extends State<LessonsPage> {
|
||||
top: false,
|
||||
child: Column(
|
||||
children: [
|
||||
// Address small (optional)
|
||||
if (schoolAddress != null && schoolAddress!.trim().isNotEmpty)
|
||||
// Riepilogo conteggi (le card pastello della webapp)
|
||||
if (summary != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 6),
|
||||
child: Text(
|
||||
schoolAddress!,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.black45,
|
||||
fontWeight: FontWeight.w500,
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 12, 4),
|
||||
child: _SummaryStrip(summary: summary!),
|
||||
),
|
||||
|
||||
// Selettore mese
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 4),
|
||||
child: _MonthPillCompact(
|
||||
label: _monthLabel(currentMonth),
|
||||
onPrev: _goPrevMonth,
|
||||
onNext: _goNextMonth,
|
||||
),
|
||||
),
|
||||
|
||||
// Bottone "Programma lezioni" (solo se ci sono ticket residui)
|
||||
if (summary != null && summary!.toSchedule > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF10B981),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
),
|
||||
icon: const Icon(Icons.add, color: Colors.white),
|
||||
label: Text(
|
||||
'Programma lezioni (${summary!.toSchedule} disponibili)',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => OrdersPage(token: widget.token),
|
||||
),
|
||||
);
|
||||
_load();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Month selector only
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 10),
|
||||
child: _MonthPillCompact(
|
||||
label: _monthLabel(currentMonth),
|
||||
onPrev: prevMonth == null
|
||||
? null
|
||||
: () {
|
||||
setState(() => currentMonth = prevMonth!);
|
||||
_load();
|
||||
},
|
||||
onNext: nextMonth == null
|
||||
? null
|
||||
: () {
|
||||
setState(() => currentMonth = nextMonth!);
|
||||
_load();
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
@@ -263,23 +290,72 @@ class _LessonsPageState extends State<LessonsPage> {
|
||||
lesson: l,
|
||||
weekday: _weekdayLabel(l.date),
|
||||
dayNum: _dayNum(l.date),
|
||||
onReschedule: l.canModify
|
||||
? () => ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Riprogramma: API dopo',
|
||||
),
|
||||
onReschedule: l.canReschedule
|
||||
? () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ReschedulePage(
|
||||
token: widget.token,
|
||||
bookingId: l.bookingId,
|
||||
serviceId: l.serviceId,
|
||||
className: l.className,
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
_load();
|
||||
}
|
||||
: null,
|
||||
onCancel: l.canModify
|
||||
? () => ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Cancella: API dopo'),
|
||||
onCancel: l.canDelete
|
||||
? () async {
|
||||
final conferma = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogCtx) => AlertDialog(
|
||||
title: const Text(
|
||||
'Cancellare la lezione?',
|
||||
),
|
||||
)
|
||||
content: Text(
|
||||
'Vuoi cancellare "${l.className}" del ${l.date}? '
|
||||
'Ricordati di riprogrammarla entro la scadenza.',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(dialogCtx, false),
|
||||
child: const Text('Annulla'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(dialogCtx, true),
|
||||
child: const Text('Cancella'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (conferma != true) return;
|
||||
try {
|
||||
await LessonsApi.cancelLesson(
|
||||
token: widget.token,
|
||||
bookingId: l.bookingId,
|
||||
);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Lezione cancellata'),
|
||||
),
|
||||
);
|
||||
_load();
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(
|
||||
SnackBar(content: Text('$e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
: null,
|
||||
);
|
||||
},
|
||||
@@ -293,55 +369,77 @@ class _LessonsPageState extends State<LessonsPage> {
|
||||
}
|
||||
}
|
||||
|
||||
class _AppDrawer extends StatelessWidget {
|
||||
final String token;
|
||||
final VoidCallback onLogout;
|
||||
|
||||
const _AppDrawer({required this.token, required this.onLogout});
|
||||
class _SummaryStrip extends StatelessWidget {
|
||||
final LessonsSummary summary;
|
||||
const _SummaryStrip({required this.summary});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Drawer(
|
||||
child: SafeArea(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
const DrawerHeader(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: Text(
|
||||
'Menu',
|
||||
style: TextStyle(fontSize: 22, fontWeight: FontWeight.w900),
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.swap_horiz),
|
||||
title: const Text('Cambia scuola'),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop(); // chiude drawer
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => SelectSchoolPage(token: token),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
final items = <_SummaryItem>[
|
||||
_SummaryItem('Acquistate', summary.purchased, const Color(0xFFE2C4FB)),
|
||||
_SummaryItem('Praticate', summary.practiced, const Color(0xFFC4E1FB)),
|
||||
_SummaryItem('Prenotate', summary.booked, const Color(0xFFCDFBC4)),
|
||||
_SummaryItem('Da confermare', summary.pending, const Color(0xFFFBFAC4)),
|
||||
_SummaryItem(
|
||||
'Da programmare',
|
||||
summary.toSchedule,
|
||||
const Color(0xFFFBE4C4),
|
||||
),
|
||||
_SummaryItem('Perse', summary.lost, const Color(0xFFFBC7C4)),
|
||||
];
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.logout),
|
||||
title: const Text('Logout'),
|
||||
onTap: onLogout,
|
||||
return SizedBox(
|
||||
height: 76,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: items.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(width: 8),
|
||||
itemBuilder: (_, i) {
|
||||
final it = items[i];
|
||||
return Container(
|
||||
width: 96,
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: it.color,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'${it.value}',
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w900,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
it.label,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SummaryItem {
|
||||
final String label;
|
||||
final int value;
|
||||
final Color color;
|
||||
_SummaryItem(this.label, this.value, this.color);
|
||||
}
|
||||
|
||||
class _MonthPillCompact extends StatelessWidget {
|
||||
final String label;
|
||||
final VoidCallback? onPrev;
|
||||
@@ -421,8 +519,8 @@ class _LessonGreenCardCompact extends StatelessWidget {
|
||||
const green = Color(0xFF10B981);
|
||||
const darkGreen = Color(0xFF065F46);
|
||||
|
||||
final level = (lesson.level ?? '').trim();
|
||||
final time = _shortTime(lesson.startTime);
|
||||
final time = _shortTime(lesson.time);
|
||||
final canModify = lesson.canReschedule || lesson.canDelete;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
@@ -441,7 +539,7 @@ class _LessonGreenCardCompact extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
child: Row(
|
||||
children: [
|
||||
// left panel smaller
|
||||
// left panel
|
||||
Container(
|
||||
width: 92,
|
||||
color: const Color(0xFFBFF3DE),
|
||||
@@ -503,7 +601,7 @@ class _LessonGreenCardCompact extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
|
||||
// right body tighter
|
||||
// right body
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
|
||||
@@ -525,52 +623,30 @@ class _LessonGreenCardCompact extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.meeting_room_outlined,
|
||||
Icons.place_outlined,
|
||||
size: 16,
|
||||
color: Colors.black54,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
(lesson.roomName ?? '').trim().isEmpty
|
||||
lesson.location.trim().isEmpty
|
||||
? 'Sala da definire'
|
||||
: lesson.roomName!,
|
||||
: lesson.location,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF404040),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
maxLines: 1,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (level.isNotEmpty) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF10B981),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
_capitalize(level),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 10,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Buttons compact (stessa riga, più piccoli)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -622,10 +698,10 @@ class _LessonGreenCardCompact extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
|
||||
if (!lesson.canModify) ...[
|
||||
if (!canModify) ...[
|
||||
const SizedBox(height: 6),
|
||||
const Text(
|
||||
'Non modificabile (entro 24 ore)',
|
||||
'Non modificabile',
|
||||
style: TextStyle(fontSize: 11, color: Colors.black54),
|
||||
),
|
||||
],
|
||||
@@ -639,30 +715,7 @@ class _LessonGreenCardCompact extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _metaRowCompact(IconData icon, String text) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: Colors.black54),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF404040),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static String _shortTime(String t) => t.length >= 5 ? t.substring(0, 5) : t;
|
||||
static String _capitalize(String s) =>
|
||||
s.isEmpty ? s : s[0].toUpperCase() + s.substring(1);
|
||||
}
|
||||
|
||||
class _EmptyState extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user