basic session create and delete
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// import 'package:drift/drift.dart' hide Column;
|
||||
import 'package:drift/drift.dart' hide Column;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:sendtrain/daos/sessions_dao.dart';
|
||||
@@ -6,24 +7,30 @@ import 'package:sendtrain/database/database.dart';
|
||||
import '../widgets/session_card.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class SessionsScreen extends StatelessWidget {
|
||||
class SessionsScreen extends StatefulWidget {
|
||||
const SessionsScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SessionsScreen> createState() => _SessionsScreenState();
|
||||
}
|
||||
|
||||
class _SessionsScreenState extends State<SessionsScreen> {
|
||||
Widget getSessionCard(session) {
|
||||
if (session != null) {
|
||||
return SessionCard(session: session);
|
||||
} else {
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: Icon(Icons.do_not_disturb_alt_outlined)
|
||||
);
|
||||
padding: EdgeInsets.all(15),
|
||||
child: Icon(Icons.do_not_disturb_alt_outlined));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<Session>>(
|
||||
future: SessionsDao(Provider.of<AppDatabase>(context)).all(),
|
||||
SessionsDao dao = SessionsDao(Provider.of<AppDatabase>(context));
|
||||
|
||||
return StreamBuilder<List<Session>>(
|
||||
stream: dao.watch(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData && snapshot.data!.isNotEmpty) {
|
||||
final sessions = snapshot.data!;
|
||||
@@ -35,8 +42,20 @@ class SessionsScreen extends StatelessWidget {
|
||||
final current = sessions.firstWhereOrNull(
|
||||
(session) => session.status == SessionStatus.started);
|
||||
|
||||
if (current == null && upcoming != null) {
|
||||
dao.createOrUpdate(SessionsCompanion(
|
||||
id: Value(upcoming.id),
|
||||
title: Value(upcoming.title),
|
||||
content: Value(upcoming.content),
|
||||
status: Value(SessionStatus.started),
|
||||
address: Value(upcoming.address),
|
||||
date: Value(upcoming.date)
|
||||
));
|
||||
}
|
||||
|
||||
List<Widget> previousSessions = List.generate(pending.length,
|
||||
(i) => SessionCard(type: 1, session: pending.elementAt(i)));
|
||||
|
||||
Widget upcomingSession = getSessionCard(upcoming);
|
||||
Widget currentSession = getSessionCard(current);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user