watchActiveRegistration method
Watches the user's active registration (where enrollment status is "在學").
Emits the most recent semester where the user is actively enrolled,
or null if no active registration exists. Automatically re-emits
when the underlying data changes (e.g., after refreshUser populates
registration data or after cache clear).
Implementation
Stream<UserRegistration?> watchActiveRegistration() {
return (_database.select(_database.userRegistrations)
..where(
(r) => r.enrollmentStatus.equalsValue(EnrollmentStatus.learning),
)
..orderBy([
(r) => OrderingTerm.desc(r.year),
(r) => OrderingTerm.desc(r.term),
])
..limit(1))
.watchSingleOrNull();
}