feat: select school before connecting timetable

This commit is contained in:
Codex
2026-10-14 20:58:47 +08:00
parent ce21cdc10c
commit d83481d965
12 changed files with 297 additions and 20 deletions
+2 -2
View File
@@ -1,2 +1,2 @@
const appVersion = '0.6.1';
const appBuildNumber = 16;
const appVersion = '0.6.2';
const appBuildNumber = 17;
+50 -4
View File
@@ -14,6 +14,7 @@ import '../features/exams/exams_page.dart';
import '../features/timetable/timetable_page.dart';
import '../features/profile/profile_page.dart';
import '../features/school/school_session.dart';
import '../features/school/school_selection_page.dart';
class HepanApp extends StatelessWidget {
const HepanApp({
@@ -66,6 +67,16 @@ class _Shell extends StatefulWidget {
class _ShellState extends State<_Shell> with WidgetsBindingObserver {
int _tab = 0;
bool _openingSchool = false;
SupportedSchool? _selectedSchool;
// Earlier imports all belong to UESTC graduate; reuse their existing term
// and session without requiring students to choose again on every refresh.
SupportedSchool? get _knownSchool =>
_selectedSchool ??
(widget.controller.snapshot.schoolTerm != null ||
widget.school?.canLogout == true
? SupportedSchool.uestcGraduate
: null);
void _selectTab(int index) {
if (index == _tab) return;
setState(() => _tab = index);
@@ -121,7 +132,41 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
}
}
void _school({bool exams = false, bool chooseTerm = false}) {
Future<void> _school({
bool exams = false,
bool chooseTerm = false,
bool selectSchool = false,
}) async {
if (_openingSchool) return;
_openingSchool = true;
try {
var selected = _knownSchool;
if (selectSchool || selected == null) {
selected = await Navigator.push<SupportedSchool>(
context,
MaterialPageRoute<SupportedSchool>(
builder: (_) => SchoolSelectionPage(selected: _knownSchool),
),
);
if (!mounted || selected == null) return;
setState(() => _selectedSchool = selected);
}
if (!mounted) return;
// The only current connector is the existing UESTC graduate workflow.
// A new catalog option must provide its own connector here.
switch (selected) {
case SupportedSchool.uestcGraduate:
await _openSchool(exams: exams, chooseTerm: chooseTerm);
}
} finally {
_openingSchool = false;
}
}
Future<void> _openSchool({
bool exams = false,
bool chooseTerm = false,
}) async {
if (widget.schoolBuilder != null) {
final term = widget.controller.snapshot.schoolTerm;
if (exams) {
@@ -135,12 +180,12 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
chooseTerm: chooseTerm || term == null,
);
}
Navigator.push(
await Navigator.push(
context,
MaterialPageRoute<void>(builder: (_) => widget.schoolBuilder!()),
);
} else {
showDialog<void>(
await showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: const Text('学校认证'),
@@ -275,7 +320,8 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
ProfilePage(
controller: widget.controller,
feedbackSender: widget.feedbackSender,
onLogin: _school,
onLogin: () => _school(selectSchool: true),
schoolName: _knownSchool?.label,
onUpdateTerm: () => _school(chooseTerm: true),
authStatus: widget.school?.statusLabel ?? '未登录',
logoutLabel: widget.school?.logoutFailed == true