officially getting data from the dbgit add . -p!
This commit is contained in:
@ -1,52 +1,113 @@
|
||||
import 'package:drift/drift.dart' hide Column;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sendtrain/database.dart';
|
||||
import '../widgets/session_card.dart';
|
||||
|
||||
class SessionsScreen extends StatelessWidget {
|
||||
const SessionsScreen({super.key});
|
||||
final AppDatabase database = AppDatabase();
|
||||
SessionsScreen({super.key});
|
||||
|
||||
Future<List<Session>> getSessions() async {
|
||||
// database.managers.sessions.filter((session) => session.status(SessionStatus.pending));
|
||||
return await database.managers.sessions.get();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Widget> previousSessions =
|
||||
List.generate(10, (i) => const SessionCard(state: 1, type: 1));
|
||||
Widget upcomingSession = const SessionCard(state: 2);
|
||||
Widget currentSession = const SessionCard();
|
||||
return FutureBuilder<List<Session>>(
|
||||
future: getSessions(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
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);
|
||||
|
||||
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))
|
||||
// Flexible(
|
||||
// child: ListView(
|
||||
// scrollDirection: Axis.vertical,
|
||||
// children: previousSessions,
|
||||
// )),
|
||||
],
|
||||
);
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
// List<Widget> previousSessions = List.generate(
|
||||
// 10, (i) => SessionCard(state: 1, type: 1, session: _sessions.first));
|
||||
// Widget upcomingSession = SessionCard(state: 2, session: _sessions.first);
|
||||
// Widget currentSession = SessionCard(session: _sessions.first);
|
||||
|
||||
// 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))
|
||||
// // Flexible(
|
||||
// // child: ListView(
|
||||
// // scrollDirection: Axis.vertical,
|
||||
// // children: previousSessions,
|
||||
// // )),
|
||||
// ],
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user