74 lines
2.9 KiB
Dart
74 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:sendtrain/database/daos/sessions_dao.dart';
|
|
import 'package:sendtrain/database/database.dart';
|
|
import '../widgets/session_card.dart';
|
|
|
|
class SessionsScreen extends StatelessWidget {
|
|
final AppDatabase database = AppDatabase();
|
|
SessionsScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder<List<Session>>(
|
|
future: SessionsDao(database).all(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData) {
|
|
database.close();
|
|
final sessions = snapshot.data!;
|
|
final pending = sessions.where((session) =>
|
|
session.status == SessionStatus.completed ||
|
|
session.status == SessionStatus.missed);
|
|
final upcoming = sessions.firstWhere(
|
|
(session) => session.status == SessionStatus.pending);
|
|
final current = sessions.firstWhere(
|
|
(session) => session.status == SessionStatus.started);
|
|
|
|
List<Widget> previousSessions = List.generate(pending.length,
|
|
(i) => SessionCard(type: 1, session: pending.elementAt(i)));
|
|
Widget upcomingSession = SessionCard(session: upcoming);
|
|
Widget currentSession = SessionCard(session: current);
|
|
|
|
database.close();
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
const Padding(
|
|
padding: EdgeInsets.fromLTRB(15, 5, 0, 0),
|
|
child: Text(
|
|
style: TextStyle(
|
|
fontSize: 25, fontWeight: FontWeight.bold),
|
|
'Current:')),
|
|
currentSession,
|
|
const Padding(
|
|
padding: EdgeInsets.fromLTRB(15, 30, 0, 0),
|
|
child: Text(
|
|
style: TextStyle(
|
|
fontSize: 25, fontWeight: FontWeight.bold),
|
|
'Upcoming:')),
|
|
upcomingSession,
|
|
const Padding(
|
|
padding: EdgeInsets.fromLTRB(15, 30, 0, 0),
|
|
child: Text(
|
|
style: TextStyle(
|
|
fontSize: 25, fontWeight: FontWeight.bold),
|
|
'Previous:')),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 160,
|
|
child: GridView.count(
|
|
padding: const EdgeInsets.fromLTRB(15, 10, 0, 0),
|
|
scrollDirection: Axis.horizontal,
|
|
crossAxisSpacing: 5,
|
|
mainAxisSpacing: 5,
|
|
crossAxisCount: 1,
|
|
children: previousSessions))
|
|
],
|
|
);
|
|
} else {
|
|
return const CircularProgressIndicator();
|
|
}
|
|
});
|
|
}
|
|
}
|