diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 854b54b6..bf37c06f 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -11,7 +11,10 @@
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
+ android:resizeableActivity="true"
android:usesCleartextTraffic="false">
+
+
result.success(info())
+ else -> result.notImplemented()
+ }
+ }
+
+ fun dispose() {
+ channel.setMethodCallHandler(null)
+ }
+
+ private fun info(): Map {
+ val display = currentDisplay()
+ val displayId = display?.displayId ?: Display.DEFAULT_DISPLAY
+ val metrics = activity.resources.displayMetrics
+ val bounds = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ activity.windowManager.currentWindowMetrics.bounds
+ } else {
+ android.graphics.Rect(0, 0, metrics.widthPixels, metrics.heightPixels)
+ }
+ return mapOf(
+ "isFlipDevice" to miuiFlag("isFlipDevice"),
+ "isRearDevice" to miuiFlag("isRearDevice"),
+ "displayId" to displayId,
+ "windowWidthPx" to bounds.width(),
+ "windowHeightPx" to bounds.height(),
+ "density" to metrics.density.toDouble(),
+ "densityDpi" to metrics.densityDpi,
+ "isDefaultDisplay" to (displayId == Display.DEFAULT_DISPLAY),
+ "isInMultiWindowMode" to activity.isInMultiWindowMode,
+ "model" to Build.MODEL,
+ "manufacturer" to Build.MANUFACTURER,
+ "sdkInt" to Build.VERSION.SDK_INT,
+ )
+ }
+
+ private fun currentDisplay(): Display? =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ activity.display
+ } else {
+ @Suppress("DEPRECATION")
+ activity.windowManager.defaultDisplay
+ }
+
+ /**
+ * The class is absent on most devices and hidden on some HyperOS builds;
+ * a failed probe simply means "not this form factor", never a crash.
+ */
+ private fun miuiFlag(method: String): Boolean = try {
+ val type = Class.forName("miui.util.MiuiMultiDisplayTypeInfo")
+ type.getMethod(method).invoke(null) as? Boolean ?: false
+ } catch (_: ReflectiveOperationException) {
+ false
+ } catch (_: SecurityException) {
+ false
+ } catch (_: LinkageError) {
+ false
+ }
+
+ private companion object {
+ const val CHANNEL = "techpie/screen_form_factor"
+ }
+}
diff --git a/docs/cover-rear-glance.md b/docs/cover-rear-glance.md
new file mode 100644
index 00000000..4ab2bbef
--- /dev/null
+++ b/docs/cover-rear-glance.md
@@ -0,0 +1,7 @@
+# Cover and rear display glance
+
+On compatible Android displays the app shows a compact course/deadline/online-payment surface. Settings configure sections and offer previews. Display classification excludes unfolded landscape windows. The main navigator stays mounted across fold/unfold, and shortcuts are consumed by the visible surface. Policy acceptance gates personal data on both surfaces; the glance never changes main-display brightness.
+
+The implementation retains upstream iOS tab stacks, online Apple Watch support, dependency pins, release version, signing and update channel. It does not add a display permission on other platforms. Offline payment remains in the full campus-card UI; previews and source checks do not verify camera scanning on every physical rear screen.
+
+Regression coverage includes classification, compact layouts, privacy, foreground/payment lifecycle and shortcut routing. Actual vendor display routing, folding and QR scans still require compatible hardware.
diff --git a/lib/features/campus_card/core/config/payment_code_preferences.dart b/lib/features/campus_card/core/config/payment_code_preferences.dart
index 38218319..e1ad698c 100644
--- a/lib/features/campus_card/core/config/payment_code_preferences.dart
+++ b/lib/features/campus_card/core/config/payment_code_preferences.dart
@@ -8,10 +8,20 @@ final maximizePaymentCodeBrightnessProvider =
final class MaximizePaymentCodeBrightnessController
extends AsyncNotifier {
+ MaximizePaymentCodeBrightnessController() : _fixed = null;
+
+ /// A controller that ignores the stored preference, for surfaces that must
+ /// never touch the main display's brightness.
+ MaximizePaymentCodeBrightnessController.fixed(bool value) : _fixed = value;
+
static const _key = 'geekpay.maximize_payment_code_brightness';
+ final bool? _fixed;
+
@override
Future build() async {
+ final fixed = _fixed;
+ if (fixed != null) return fixed;
final preferences = await SharedPreferences.getInstance();
return preferences.getBool(_key) ?? false;
}
diff --git a/lib/features/campus_card/presentation/widgets/payment_code_qr.dart b/lib/features/campus_card/presentation/widgets/payment_code_qr.dart
new file mode 100644
index 00000000..0b6327d4
--- /dev/null
+++ b/lib/features/campus_card/presentation/widgets/payment_code_qr.dart
@@ -0,0 +1,174 @@
+import 'dart:async';
+import 'dart:convert';
+import 'dart:typed_data';
+
+import 'package:flutter/material.dart';
+import 'package:qr_flutter/qr_flutter.dart';
+
+import '../theme/tokens.dart';
+
+/// The campus payment QR, shared by the full pass and the glance surface.
+///
+/// [qrKey] defaults to the key the full pass has always exposed; the glance
+/// passes its own key so a test can tell the two surfaces apart.
+final class PaymentCodeQr extends StatefulWidget {
+ const PaymentCodeQr({
+ super.key,
+ required this.payload,
+ required this.binaryPayload,
+ required this.size,
+ required this.onTap,
+ this.qrKey = const Key('payment-code-qr'),
+ });
+
+ final String payload;
+ final bool binaryPayload;
+ final double size;
+ final VoidCallback onTap;
+ final Key qrKey;
+
+ @override
+ State createState() => _PaymentCodeQrState();
+}
+
+class _PaymentCodeQrState extends State {
+ late Widget _image;
+
+ @override
+ void initState() {
+ super.initState();
+ _image = _createImage();
+ }
+
+ @override
+ void didUpdateWidget(PaymentCodeQr oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.payload != widget.payload ||
+ oldWidget.binaryPayload != widget.binaryPayload) {
+ _image = _createImage();
+ }
+ }
+
+ Widget _createImage() => widget.binaryPayload
+ ? QrImageView.withQr(
+ qr: QrCode.fromUint8List(
+ data: Uint8List.fromList(latin1.encode(widget.payload)),
+ errorCorrectLevel: QrErrorCorrectLevel.L,
+ ),
+ padding: EdgeInsets.zero,
+ eyeStyle: const QrEyeStyle(
+ eyeShape: QrEyeShape.square,
+ color: GpTokens.campusRed,
+ ),
+ dataModuleStyle: const QrDataModuleStyle(
+ dataModuleShape: QrDataModuleShape.square,
+ color: GpTokens.campusRed,
+ ),
+ backgroundColor: GpTokens.cardCanvas,
+ )
+ : QrImageView(
+ data: widget.payload,
+ version: QrVersions.auto,
+ padding: EdgeInsets.zero,
+ eyeStyle: const QrEyeStyle(
+ eyeShape: QrEyeShape.square,
+ color: GpTokens.campusRed,
+ ),
+ dataModuleStyle: const QrDataModuleStyle(
+ dataModuleShape: QrDataModuleShape.square,
+ color: GpTokens.campusRed,
+ ),
+ backgroundColor: GpTokens.cardCanvas,
+ );
+
+ @override
+ Widget build(BuildContext context) {
+ return Semantics(
+ button: true,
+ label: '轻触二维码刷新',
+ child: GestureDetector(
+ onTap: widget.onTap,
+ child: Container(
+ key: widget.qrKey,
+ width: widget.size,
+ height: widget.size,
+ color: GpTokens.cardCanvas,
+ padding: EdgeInsets.all(widget.size * 0.035),
+ child: _image,
+ ),
+ ),
+ );
+ }
+}
+
+/// Thirty-second countdown shown under an online code.
+final class PaymentCodeCountdown extends StatefulWidget {
+ const PaymentCodeCountdown({
+ super.key,
+ required this.generation,
+ required this.active,
+ required this.style,
+ this.seconds = 30,
+ });
+
+ final int generation;
+ final bool active;
+ final TextStyle style;
+ final int seconds;
+
+ @override
+ State createState() => _PaymentCodeCountdownState();
+}
+
+class _PaymentCodeCountdownState extends State {
+ Timer? _timer;
+ late int _remaining;
+
+ @override
+ void initState() {
+ super.initState();
+ _remaining = widget.seconds;
+ _startTimer();
+ }
+
+ @override
+ void didUpdateWidget(PaymentCodeCountdown oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.generation != widget.generation ||
+ oldWidget.seconds != widget.seconds) {
+ _remaining = widget.seconds;
+ _startTimer();
+ } else if (oldWidget.active != widget.active) {
+ _startTimer();
+ }
+ }
+
+ void _startTimer() {
+ _timer?.cancel();
+ if (!widget.active || _remaining <= 1) return;
+ final initial = _remaining;
+ _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
+ final next = (initial - timer.tick).clamp(1, widget.seconds);
+ setState(() => _remaining = next);
+ if (_remaining == 1) timer.cancel();
+ });
+ }
+
+ @override
+ void dispose() {
+ _timer?.cancel();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) => SizedBox(
+ width: double.infinity,
+ child: RepaintBoundary(
+ child: Text(
+ '$_remaining秒后刷新',
+ textAlign: TextAlign.center,
+ style: widget.style,
+ ),
+ ),
+ );
+}
diff --git a/lib/features/glance/application/glance_snapshot_builder.dart b/lib/features/glance/application/glance_snapshot_builder.dart
new file mode 100644
index 00000000..d9d9eaae
--- /dev/null
+++ b/lib/features/glance/application/glance_snapshot_builder.dart
@@ -0,0 +1,76 @@
+import '../../../models/assignment.dart';
+import '../../../models/course.dart';
+import '../../../models/course_table.dart';
+import '../../../models/custom_course.dart';
+import '../../../services/schedule_timeline_service.dart';
+import '../domain/glance_snapshot.dart';
+import '../presentation/glance_formatters.dart';
+
+/// Builds the glance snapshot from raw service data.
+///
+/// The course merge and state rules come from [ScheduleTimeline], the same
+/// source Home and the band app use. Deadline filtering is done by the caller
+/// through [AssignmentService.visibleAssignments]/`isCompleted` so hidden and
+/// locally completed items never leak into the small surface.
+final class GlanceSnapshotBuilder {
+ const GlanceSnapshotBuilder._();
+
+ static GlanceSnapshot build({
+ required CourseTable? courseTable,
+ required List customCourses,
+ required DateTime? termBegin,
+ required int? week,
+ required List rawAssignments,
+ required List pendingAssignments,
+ required String? semesterId,
+ required DateTime now,
+ required bool loggedIn,
+ required bool inTerm,
+ required bool scheduleLoading,
+ required String? scheduleError,
+ required bool assignmentsLoading,
+ required String? assignmentsError,
+ }) {
+ final courses = ScheduleTimeline.todayCourses(
+ table: courseTable,
+ customCourses: customCourses,
+ week: week,
+ termBegin: termBegin,
+ assignments: rawAssignments,
+ semesterId: semesterId,
+ now: now,
+ );
+ final pending = [...pendingAssignments]
+ ..sort((a, b) => a.due.compareTo(b.due));
+
+ return GlanceSnapshot(
+ now: now,
+ week: week,
+ inTerm: inTerm,
+ loggedIn: loggedIn,
+ courses: [
+ for (final course in courses)
+ GlanceCourse(course: course, state: _stateOf(course, now)),
+ ],
+ pendingAssignments: [
+ for (final assignment in pending)
+ GlanceAssignment(
+ assignment: assignment,
+ dueLabel: formatGlanceDue(assignment.due, now),
+ ),
+ ],
+ scheduleLoading: scheduleLoading,
+ scheduleError: scheduleError,
+ assignmentsLoading: assignmentsLoading,
+ assignmentsError: assignmentsError,
+ );
+ }
+
+ static GlanceCourseState _stateOf(Course course, DateTime now) =>
+ switch (ScheduleTimeline.courseState(course, now)) {
+ 'past' => GlanceCourseState.past,
+ 'ongoing' => GlanceCourseState.ongoing,
+ 'soon' => GlanceCourseState.soon,
+ _ => GlanceCourseState.upcoming,
+ };
+}
diff --git a/lib/features/glance/domain/glance_snapshot.dart b/lib/features/glance/domain/glance_snapshot.dart
new file mode 100644
index 00000000..e680c82a
--- /dev/null
+++ b/lib/features/glance/domain/glance_snapshot.dart
@@ -0,0 +1,77 @@
+import '../../../models/assignment.dart';
+import '../../../models/course.dart';
+
+enum GlanceCourseState { past, ongoing, soon, upcoming }
+
+final class GlanceCourse {
+ const GlanceCourse({required this.course, required this.state});
+
+ final Course course;
+ final GlanceCourseState state;
+
+ bool get isPast => state == GlanceCourseState.past;
+
+ bool get isOngoing => state == GlanceCourseState.ongoing;
+}
+
+final class GlanceAssignment {
+ const GlanceAssignment({required this.assignment, required this.dueLabel});
+
+ final Assignment assignment;
+ final String dueLabel;
+}
+
+/// A point-in-time view of today's schedule and pending deadlines.
+final class GlanceSnapshot {
+ const GlanceSnapshot({
+ required this.now,
+ required this.week,
+ required this.inTerm,
+ required this.loggedIn,
+ required this.courses,
+ required this.pendingAssignments,
+ required this.scheduleLoading,
+ required this.scheduleError,
+ required this.assignmentsLoading,
+ required this.assignmentsError,
+ });
+
+ final DateTime now;
+ final int? week;
+ final bool inTerm;
+ final bool loggedIn;
+ final List courses;
+ final List pendingAssignments;
+ final bool scheduleLoading;
+ final String? scheduleError;
+ final bool assignmentsLoading;
+ final String? assignmentsError;
+
+ bool get hasCourses => courses.isNotEmpty;
+
+ bool get hasPending => pendingAssignments.isNotEmpty;
+
+ GlanceCourse? get currentCourse {
+ for (final course in courses) {
+ if (course.isOngoing) return course;
+ }
+ return null;
+ }
+
+ GlanceCourse? get nextCourse {
+ for (final course in courses) {
+ if (course.state == GlanceCourseState.soon ||
+ course.state == GlanceCourseState.upcoming) {
+ return course;
+ }
+ }
+ return null;
+ }
+
+ /// Today's courses that are still ongoing or upcoming, in start order.
+ List get activeCourses =>
+ [for (final course in courses) if (!course.isPast) course];
+
+ /// The course to lead with: the one in progress, otherwise the next one.
+ GlanceCourse? get leadCourse => currentCourse ?? nextCourse;
+}
diff --git a/lib/features/glance/presentation/cover_glance_layout.dart b/lib/features/glance/presentation/cover_glance_layout.dart
new file mode 100644
index 00000000..3b1b84cc
--- /dev/null
+++ b/lib/features/glance/presentation/cover_glance_layout.dart
@@ -0,0 +1,732 @@
+import 'package:flutter/material.dart';
+
+import '../../../models/course.dart';
+import '../domain/glance_snapshot.dart';
+import 'glance_formatters.dart';
+import 'glance_widgets.dart';
+
+/// Cover pages are designed for the MIX Flip panel: 506 x 439 dp, wider than
+/// it is tall. Each page splits into a leading card and a vertical queue so the
+/// extra width carries information instead of stretching a single column.
+class CoverCoursesPage extends StatelessWidget {
+ const CoverCoursesPage({
+ super.key,
+ required this.snapshot,
+ this.onRetry,
+ });
+
+ final GlanceSnapshot snapshot;
+ final VoidCallback? onRetry;
+
+ @override
+ Widget build(BuildContext context) {
+ final unavailable = glanceUnavailableState(
+ snapshot,
+ courses: true,
+ compact: false,
+ onRetry: onRetry,
+ );
+ if (unavailable != null) return unavailable;
+
+ final lead = snapshot.leadCourse;
+ if (lead == null) {
+ return GlanceMessage(
+ icon: Icons.nights_stay_outlined,
+ title: '今天的课已结束',
+ subtitle: '今天共 ${snapshot.courses.length} 节课',
+ );
+ }
+
+ final rest = [];
+ var skippedLead = false;
+ for (final course in snapshot.activeCourses) {
+ if (!skippedLead && identical(course, lead)) {
+ skippedLead = true;
+ continue;
+ }
+ rest.add(course);
+ }
+
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(16, 6, 16, 10),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Expanded(
+ flex: 3,
+ child: _LeadCourseCard(
+ course: lead,
+ totalCourses: snapshot.courses.length,
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ flex: 2,
+ child: _CourseQueue(courses: rest),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _LeadCourseCard extends StatelessWidget {
+ const _LeadCourseCard({
+ required this.course,
+ required this.totalCourses,
+ });
+
+ final GlanceCourse course;
+ final int totalCourses;
+
+ @override
+ Widget build(BuildContext context) {
+ final scheme = Theme.of(context).colorScheme;
+ final background = course.course.color.containerColor(scheme);
+ final foreground = course.course.color.onContainerColor(scheme);
+ final location =
+ course.course.location.isEmpty ? '地点待定' : course.course.location;
+
+ return Container(
+ padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
+ decoration: BoxDecoration(
+ color: background,
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ _StatePill(label: _stateLabel(course.state), color: foreground),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Text(
+ formatGlanceCourseTime(course.course),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.end,
+ style: TextStyle(
+ fontSize: 12,
+ fontWeight: FontWeight.w600,
+ color: foreground.withValues(alpha: 0.78),
+ ),
+ ),
+ ),
+ ],
+ ),
+ Expanded(
+ child: Align(
+ alignment: Alignment.centerLeft,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ course.course.name,
+ maxLines: 3,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 25,
+ height: 1.12,
+ fontWeight: FontWeight.w700,
+ color: foreground,
+ ),
+ ),
+ const SizedBox(height: 8),
+ Row(
+ children: [
+ Icon(
+ Icons.place_outlined,
+ size: 14,
+ color: foreground.withValues(alpha: 0.8),
+ ),
+ const SizedBox(width: 4),
+ Expanded(
+ child: Text(
+ location,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 12,
+ color: foreground.withValues(alpha: 0.8),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ ),
+ Divider(
+ height: 17,
+ thickness: 1,
+ color: foreground.withValues(alpha: 0.12),
+ ),
+ Text(
+ '今天共 $totalCourses 节课',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10,
+ fontWeight: FontWeight.w600,
+ color: foreground.withValues(alpha: 0.7),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _StatePill extends StatelessWidget {
+ const _StatePill({required this.label, required this.color});
+
+ final String label;
+ final Color color;
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
+ decoration: BoxDecoration(
+ color: color.withValues(alpha: 0.12),
+ borderRadius: BorderRadius.circular(999),
+ ),
+ child: Text(
+ label,
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 10.5,
+ fontWeight: FontWeight.w600,
+ color: color,
+ ),
+ ),
+ );
+ }
+}
+
+class _CourseQueue extends StatelessWidget {
+ const _CourseQueue({required this.courses});
+
+ final List courses;
+
+ @override
+ Widget build(BuildContext context) {
+ final scheme = Theme.of(context).colorScheme;
+ final shown = courses.take(4).toList();
+ final hidden = courses.length - shown.length;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(
+ '之后',
+ style: TextStyle(
+ fontSize: 11,
+ fontWeight: FontWeight.w600,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ const Spacer(),
+ Text(
+ '${courses.length} 节',
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 7),
+ Expanded(
+ child: shown.isEmpty
+ ? Center(
+ child: Text(
+ '之后没有课了',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 11,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ )
+ : ListView.separated(
+ padding: EdgeInsets.zero,
+ itemCount: shown.length,
+ separatorBuilder: (_, __) => const SizedBox(height: 7),
+ itemBuilder: (context, index) =>
+ _CourseQueueRow(course: shown[index]),
+ ),
+ ),
+ if (hidden > 0) ...[
+ const SizedBox(height: 4),
+ Text(
+ '还有 $hidden 节课',
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ],
+ );
+ }
+}
+
+class _CourseQueueRow extends StatelessWidget {
+ const _CourseQueueRow({required this.course});
+
+ final GlanceCourse course;
+
+ @override
+ Widget build(BuildContext context) {
+ final scheme = Theme.of(context).colorScheme;
+ return Container(
+ padding: const EdgeInsets.fromLTRB(9, 9, 10, 9),
+ decoration: BoxDecoration(
+ color: scheme.surfaceContainerHighest.withValues(alpha: 0.55),
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Row(
+ children: [
+ Container(
+ width: 3,
+ height: 36,
+ decoration: BoxDecoration(
+ color: course.course.color.containerColor(scheme),
+ borderRadius: BorderRadius.circular(3),
+ ),
+ ),
+ const SizedBox(width: 9),
+ SizedBox(
+ width: 42,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ FittedBox(
+ fit: BoxFit.scaleDown,
+ alignment: Alignment.centerLeft,
+ child: Text(
+ course.course.startTime,
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 12,
+ fontWeight: FontWeight.w600,
+ color: scheme.onSurface,
+ ),
+ ),
+ ),
+ FittedBox(
+ fit: BoxFit.scaleDown,
+ alignment: Alignment.centerLeft,
+ child: Text(
+ course.course.endTime,
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(width: 6),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ course.course.name,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 12.5,
+ height: 1.18,
+ fontWeight: FontWeight.w600,
+ color: scheme.onSurface,
+ ),
+ ),
+ if (course.course.location.isNotEmpty)
+ Text(
+ course.course.location,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class CoverAssignmentsPage extends StatelessWidget {
+ const CoverAssignmentsPage({
+ super.key,
+ required this.snapshot,
+ this.onRetry,
+ });
+
+ final GlanceSnapshot snapshot;
+ final VoidCallback? onRetry;
+
+ @override
+ Widget build(BuildContext context) {
+ final unavailable = glanceUnavailableState(
+ snapshot,
+ courses: false,
+ compact: false,
+ onRetry: onRetry,
+ );
+ if (unavailable != null) return unavailable;
+
+ final items = snapshot.pendingAssignments;
+ final lead = items.first;
+ final rest = items.skip(1).toList();
+
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(16, 6, 16, 10),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Expanded(
+ flex: 3,
+ child: _LeadAssignmentCard(
+ item: lead,
+ now: snapshot.now,
+ total: items.length,
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ flex: 2,
+ child: _AssignmentQueue(
+ items: rest,
+ now: snapshot.now,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _LeadAssignmentCard extends StatelessWidget {
+ const _LeadAssignmentCard({
+ required this.item,
+ required this.now,
+ required this.total,
+ });
+
+ final GlanceAssignment item;
+ final DateTime now;
+ final int total;
+
+ @override
+ Widget build(BuildContext context) {
+ final scheme = Theme.of(context).colorScheme;
+ final urgency = _urgencyColor(item.assignment.due, now, scheme);
+ final course = item.assignment.course;
+
+ return ClipRRect(
+ borderRadius: BorderRadius.circular(20),
+ child: ColoredBox(
+ color: scheme.surfaceContainerHighest.withValues(alpha: 0.55),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ SizedBox(width: 4, child: ColoredBox(color: urgency)),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(14, 13, 16, 14),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Container(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 8,
+ vertical: 3,
+ ),
+ decoration: BoxDecoration(
+ color: urgency.withValues(alpha: 0.12),
+ borderRadius: BorderRadius.circular(999),
+ ),
+ child: Text(
+ '最紧急',
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 10.5,
+ fontWeight: FontWeight.w600,
+ color: urgency,
+ ),
+ ),
+ ),
+ const Spacer(),
+ Text(
+ '共 $total 项',
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ Expanded(
+ child: Align(
+ alignment: Alignment.centerLeft,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ item.assignment.title,
+ maxLines: 3,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 20,
+ height: 1.2,
+ fontWeight: FontWeight.w700,
+ color: scheme.onSurface,
+ ),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ course.isEmpty
+ ? item.assignment.kind.label
+ : '$course · ${item.assignment.kind.label}',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 11,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ Divider(
+ height: 17,
+ thickness: 1,
+ color: scheme.outlineVariant.withValues(alpha: 0.6),
+ ),
+ Row(
+ children: [
+ Text(
+ '截止',
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ const SizedBox(width: 6),
+ Expanded(
+ child: Text(
+ item.dueLabel,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 13,
+ fontWeight: FontWeight.w700,
+ color: urgency,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _AssignmentQueue extends StatelessWidget {
+ const _AssignmentQueue({required this.items, required this.now});
+
+ final List items;
+ final DateTime now;
+
+ @override
+ Widget build(BuildContext context) {
+ final scheme = Theme.of(context).colorScheme;
+ final shown = items.take(3).toList();
+ final hidden = items.length - shown.length;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(
+ '后续',
+ style: TextStyle(
+ fontSize: 11,
+ fontWeight: FontWeight.w600,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ const Spacer(),
+ Text(
+ '${items.length} 项',
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 7),
+ Expanded(
+ child: shown.isEmpty
+ ? Center(
+ child: Text(
+ '没有更多待办',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 11,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ )
+ : ListView.separated(
+ padding: EdgeInsets.zero,
+ itemCount: shown.length,
+ separatorBuilder: (_, __) => const SizedBox(height: 7),
+ itemBuilder: (context, index) => _AssignmentQueueRow(
+ item: shown[index],
+ now: now,
+ ),
+ ),
+ ),
+ if (hidden > 0) ...[
+ const SizedBox(height: 4),
+ Text(
+ '还有 $hidden 项',
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ],
+ );
+ }
+}
+
+class _AssignmentQueueRow extends StatelessWidget {
+ const _AssignmentQueueRow({
+ required this.item,
+ required this.now,
+ });
+
+ final GlanceAssignment item;
+ final DateTime now;
+
+ @override
+ Widget build(BuildContext context) {
+ final scheme = Theme.of(context).colorScheme;
+ final urgency = _urgencyColor(item.assignment.due, now, scheme);
+ final course = item.assignment.course;
+ return Container(
+ padding: const EdgeInsets.fromLTRB(9, 8, 10, 8),
+ decoration: BoxDecoration(
+ color: scheme.surfaceContainerHighest.withValues(alpha: 0.55),
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Container(
+ width: 3,
+ height: 34,
+ margin: const EdgeInsets.only(top: 1),
+ decoration: BoxDecoration(
+ color: urgency,
+ borderRadius: BorderRadius.circular(3),
+ ),
+ ),
+ const SizedBox(width: 9),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ item.assignment.title,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 12.5,
+ height: 1.2,
+ fontWeight: FontWeight.w600,
+ color: scheme.onSurface,
+ ),
+ ),
+ const SizedBox(height: 3),
+ Text(
+ course.isEmpty
+ ? item.assignment.kind.label
+ : '$course · ${item.assignment.kind.label}',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ const SizedBox(height: 2),
+ Text(
+ item.dueLabel,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10.5,
+ fontWeight: FontWeight.w600,
+ color: urgency,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+String _stateLabel(GlanceCourseState state) => switch (state) {
+ GlanceCourseState.ongoing => '正在上课',
+ GlanceCourseState.soon => '即将开始',
+ GlanceCourseState.upcoming => '下一节',
+ GlanceCourseState.past => '已结束',
+ };
+
+Color _urgencyColor(DateTime due, DateTime now, ColorScheme scheme) {
+ final today = DateTime(now.year, now.month, now.day);
+ final target = DateTime(due.year, due.month, due.day);
+ final days = target.difference(today).inDays;
+ if (days <= 0) return scheme.error;
+ if (days == 1) return scheme.tertiary;
+ return scheme.onSurfaceVariant;
+}
diff --git a/lib/features/glance/presentation/glance_formatters.dart b/lib/features/glance/presentation/glance_formatters.dart
new file mode 100644
index 00000000..1f2e1758
--- /dev/null
+++ b/lib/features/glance/presentation/glance_formatters.dart
@@ -0,0 +1,41 @@
+import '../../../models/course.dart';
+
+const _weekdays = ['一', '二', '三', '四', '五', '六', '日'];
+
+String formatGlanceClock(DateTime time) =>
+ '${time.hour.toString().padLeft(2, '0')}:'
+ '${time.minute.toString().padLeft(2, '0')}';
+
+String formatGlanceWeekday(DateTime time) => '周${_weekdays[time.weekday - 1]}';
+
+String formatGlanceMonthDay(DateTime time) =>
+ '${time.month.toString().padLeft(2, '0')}/'
+ '${time.day.toString().padLeft(2, '0')}';
+
+/// `周三 · 10/28 · 第9周`; the week suffix disappears outside the term.
+String formatGlanceDateLine({
+ required DateTime now,
+ required int? week,
+ required bool inTerm,
+}) {
+ final parts = [
+ formatGlanceWeekday(now),
+ formatGlanceMonthDay(now),
+ if (inTerm && week != null) '第$week周',
+ ];
+ return parts.join(' · ');
+}
+
+/// `今天 14:00`, `明天 09:00`, `10/30 23:59`.
+String formatGlanceDue(DateTime due, DateTime now) {
+ final today = DateTime(now.year, now.month, now.day);
+ final target = DateTime(due.year, due.month, due.day);
+ final days = target.difference(today).inDays;
+ final clock = formatGlanceClock(due);
+ if (days <= 0) return '今天 $clock';
+ if (days == 1) return '明天 $clock';
+ return '${formatGlanceMonthDay(due)} $clock';
+}
+
+String formatGlanceCourseTime(Course course) =>
+ '${course.startTime}–${course.endTime}';
diff --git a/lib/features/glance/presentation/glance_payment_card.dart b/lib/features/glance/presentation/glance_payment_card.dart
new file mode 100644
index 00000000..8485125b
--- /dev/null
+++ b/lib/features/glance/presentation/glance_payment_card.dart
@@ -0,0 +1,215 @@
+import 'dart:math' as math;
+
+import 'package:flutter/material.dart';
+
+import '../../campus_card/presentation/theme/tokens.dart';
+import '../../campus_card/presentation/widgets/payment_code_qr.dart';
+
+/// Renders an online payment code on a light card that stays readable on both
+/// the cover and the rear screen. The caller supplies the data and the
+/// countdown widget, so the preview can reuse the exact layout without polling.
+class GlancePaymentCard extends StatelessWidget {
+ const GlancePaymentCard({
+ super.key,
+ required this.payload,
+ required this.binaryPayload,
+ required this.statusLabel,
+ required this.hint,
+ required this.onTap,
+ this.balanceText,
+ this.countdown,
+ this.qrKey = const Key('glance-payment-qr'),
+ });
+
+ final String payload;
+ final bool binaryPayload;
+ final String statusLabel;
+ final String hint;
+ final VoidCallback onTap;
+ final String? balanceText;
+ final Widget? countdown;
+ final Key qrKey;
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ decoration: BoxDecoration(
+ color: GpTokens.cardCanvas,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ padding: const EdgeInsets.all(12),
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final landscape = constraints.maxWidth > constraints.maxHeight;
+ final large = landscape &&
+ constraints.maxWidth >= 380 &&
+ constraints.maxHeight >= 300;
+ if (landscape) {
+ final qrSize = math
+ .min(constraints.maxWidth * 0.55, constraints.maxHeight - 10)
+ .clamp(90.0, 280.0)
+ .toDouble();
+ return Row(
+ children: [
+ PaymentCodeQr(
+ payload: payload,
+ binaryPayload: binaryPayload,
+ size: qrSize,
+ onTap: onTap,
+ qrKey: qrKey,
+ ),
+ SizedBox(width: large ? 18 : 10),
+ Expanded(
+ child: _PaymentDetails(
+ statusLabel: statusLabel,
+ balanceText: balanceText,
+ hint: hint,
+ countdown: countdown,
+ compact: true,
+ large: large,
+ ),
+ ),
+ ],
+ );
+ }
+
+ final qrSize = math
+ .min(constraints.maxWidth - 10, constraints.maxHeight * 0.60)
+ .clamp(120.0, 260.0)
+ .toDouble();
+ return Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ _PaymentDetails(
+ statusLabel: statusLabel,
+ balanceText: balanceText,
+ hint: null,
+ countdown: null,
+ compact: false,
+ large: false,
+ ),
+ const SizedBox(height: 6),
+ PaymentCodeQr(
+ payload: payload,
+ binaryPayload: binaryPayload,
+ size: qrSize,
+ onTap: onTap,
+ qrKey: qrKey,
+ ),
+ if (countdown != null) ...[
+ const SizedBox(height: 4),
+ countdown!,
+ ],
+ const SizedBox(height: 2),
+ Text(
+ hint,
+ textAlign: TextAlign.center,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 9,
+ color: GpTokens.campusRed.withValues(alpha: 0.55),
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ );
+ }
+}
+
+class _PaymentDetails extends StatelessWidget {
+ const _PaymentDetails({
+ required this.statusLabel,
+ required this.balanceText,
+ required this.hint,
+ required this.countdown,
+ required this.compact,
+ required this.large,
+ });
+
+ final String statusLabel;
+ final String? balanceText;
+ final String? hint;
+ final Widget? countdown;
+ final bool compact;
+ final bool large;
+
+ @override
+ Widget build(BuildContext context) {
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment:
+ compact ? CrossAxisAlignment.start : CrossAxisAlignment.center,
+ children: [
+ Text(
+ statusLabel,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: compact ? (large ? 12 : 10) : 11,
+ fontWeight: FontWeight.w600,
+ color: GpTokens.campusRed,
+ ),
+ ),
+ if (balanceText != null) ...[
+ SizedBox(height: compact ? (large ? 4 : 2) : 1),
+ Text(
+ balanceText!,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: compact ? (large ? 26 : 18) : 20,
+ fontWeight: FontWeight.w700,
+ color: GpTokens.campusRed,
+ fontFeatures: const [FontFeature.tabularFigures()],
+ ),
+ ),
+ ],
+ if (countdown != null) ...[
+ SizedBox(height: large ? 6 : 3),
+ countdown!,
+ ],
+ if (hint != null) ...[
+ SizedBox(height: large ? 6 : 4),
+ Text(
+ hint!,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: large ? 10 : 9,
+ color: GpTokens.campusRed.withValues(alpha: 0.55),
+ ),
+ ),
+ ],
+ ],
+ );
+ }
+}
+
+/// Static preview used by the settings page: a real QR of a harmless sample
+/// payload, no auth, no polling, and no offline quota.
+class GlancePaymentPreviewCard extends StatelessWidget {
+ const GlancePaymentPreviewCard({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return GlancePaymentCard(
+ payload: 'https://techpie.geekpie.club',
+ binaryPayload: false,
+ statusLabel: '示例消费码',
+ balanceText: '¥ 128.00',
+ hint: '预览,不会生成付款码',
+ countdown: Text(
+ '30秒后刷新',
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ fontSize: 10,
+ color: GpTokens.campusRed.withValues(alpha: 0.62),
+ ),
+ ),
+ onTap: () {},
+ );
+ }
+}
diff --git a/lib/features/glance/presentation/glance_payment_view.dart b/lib/features/glance/presentation/glance_payment_view.dart
new file mode 100644
index 00000000..efc433ff
--- /dev/null
+++ b/lib/features/glance/presentation/glance_payment_view.dart
@@ -0,0 +1,296 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+
+import '../../campus_card/app/app_providers.dart';
+import '../../campus_card/app/app_runtime.dart';
+import '../../campus_card/core/config/payment_code_preferences.dart';
+import '../../campus_card/domain/models/auth_models.dart';
+import '../../campus_card/domain/models/card_models.dart';
+import '../../campus_card/domain/models/payment_models.dart';
+import '../../campus_card/presentation/theme/theme.dart';
+import '../../campus_card/presentation/theme/tokens.dart';
+import '../../campus_card/presentation/widgets/apple_wallet_components.dart';
+import '../../campus_card/presentation/widgets/payment_code_qr.dart';
+import 'glance_payment_card.dart';
+import 'glance_widgets.dart';
+
+/// Online payment code for the cover / rear screen.
+///
+/// This view deliberately watches only authentication, the card summary and
+/// the online payment controller. Offline codes stay in the full campus-card
+/// page so glancing at the small screen can never spend an offline use.
+class GlancePaymentView extends StatelessWidget {
+ const GlancePaymentView({super.key, required this.runtime});
+
+ final AppRuntime runtime;
+
+ @override
+ Widget build(BuildContext context) {
+ return ProviderScope(
+ overrides: [
+ appRuntimeProvider.overrideWithValue(runtime),
+ maximizePaymentCodeBrightnessProvider.overrideWith(
+ () => MaximizePaymentCodeBrightnessController.fixed(false),
+ ),
+ ],
+ child: Builder(
+ builder: (context) {
+ final host = Theme.of(context);
+ return Theme(
+ data: GeekPayTheme.inherit(host),
+ child: const _GlancePaymentBody(),
+ );
+ },
+ ),
+ );
+ }
+}
+
+/// The small surface must never change the main display's brightness.
+class _GlancePaymentBody extends ConsumerStatefulWidget {
+ const _GlancePaymentBody();
+
+ @override
+ ConsumerState<_GlancePaymentBody> createState() =>
+ _GlancePaymentBodyState();
+}
+
+class _GlancePaymentBodyState extends ConsumerState<_GlancePaymentBody>
+ with WidgetsBindingObserver {
+ bool _tickerEnabled = true;
+ bool _foreground = true;
+ bool _entered = false;
+ int _revision = 0;
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addObserver(this);
+ _foreground =
+ WidgetsBinding.instance.lifecycleState == null ||
+ WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed;
+ }
+
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ _tickerEnabled = TickerMode.valuesOf(context).enabled;
+ _scheduleSync();
+ }
+
+ @override
+ void didChangeAppLifecycleState(AppLifecycleState state) {
+ _foreground = state == AppLifecycleState.resumed;
+ _scheduleSync();
+ }
+
+ @override
+ void dispose() {
+ WidgetsBinding.instance.removeObserver(this);
+ super.dispose();
+ }
+
+ void _scheduleSync() {
+ final revision = ++_revision;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) unawaited(_applyActivity(revision));
+ });
+ }
+
+ Future _applyActivity(int revision) async {
+ if (!mounted || revision != _revision) return;
+ final auth = ref.read(authControllerProvider).valueOrNull;
+ final authenticated = auth?.state == AuthState.authenticated;
+ final shouldRun = _tickerEnabled && _foreground && authenticated;
+ if (shouldRun == _entered) return;
+ final notifier = ref.read(paymentCodeControllerProvider.notifier);
+ if (shouldRun) {
+ _entered = true;
+ try {
+ await notifier.enter(online: true);
+ } catch (_) {
+ _entered = false;
+ }
+ } else {
+ _entered = false;
+ await notifier.leave();
+ }
+ if (mounted && revision == _revision) setState(() {});
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ ref.listen(authControllerProvider, (_, __) => _scheduleSync());
+ final auth = ref.watch(authControllerProvider);
+ final card = ref.watch(cardControllerProvider);
+ final payment = ref.watch(paymentCodeControllerProvider);
+
+ final snapshot = auth.valueOrNull;
+ if (snapshot == null) {
+ if (auth.hasError) {
+ return const GlanceMessage(
+ icon: Icons.credit_card_off_outlined,
+ title: '校园卡状态不可用',
+ subtitle: '请展开手机重试',
+ );
+ }
+ return const GlanceLoading(label: '正在读取校园卡…');
+ }
+
+ switch (snapshot.state) {
+ case AuthState.signingIn:
+ return const GlanceLoading(label: '正在登录校园卡…');
+ case AuthState.authenticated:
+ break;
+ case AuthState.expired:
+ return const GlanceMessage(
+ icon: Icons.lock_clock_outlined,
+ title: '校园卡登录已过期',
+ subtitle: '请展开手机,在完整 App 中重新登录',
+ );
+ case AuthState.signedOut:
+ case AuthState.unconfigured:
+ return const GlanceMessage(
+ icon: Icons.credit_card_outlined,
+ title: '校园卡未登录',
+ subtitle: '请展开手机,在完整 App 中登录',
+ );
+ }
+
+ final cardValue = card.valueOrNull;
+ final cardBlocked =
+ cardValue != null && !cardValue.status.permitsPayment;
+ final balance = cardValue != null && cardValue.detailsAvailable
+ ? formatMoneyFen(cardValue.balance.value)
+ : null;
+
+ if (payment.phase == PaymentCodePhase.activationRequired) {
+ return const GlanceMessage(
+ icon: Icons.wifi_tethering_error_rounded,
+ title: '付款码未开通',
+ subtitle: '请在完整 App 中完成开通',
+ );
+ }
+
+ if (payment.phase == PaymentCodePhase.succeeded && payment.result != null) {
+ return _PaymentSuccess(result: payment.result!);
+ }
+
+ final frame = payment.frame;
+ if (frame == null) {
+ if (payment.phase == PaymentCodePhase.failed) {
+ return GlanceMessage(
+ icon: Icons.qr_code_2_outlined,
+ title: '付款码加载失败',
+ subtitle: payment.message,
+ action: TextButton(
+ onPressed: () => unawaited(_retry()),
+ child: const Text('重试'),
+ ),
+ );
+ }
+ return const GlanceLoading(label: '正在生成付款码…');
+ }
+
+ final disconnected =
+ payment.connectionState == PaymentConnectionState.disconnected;
+ final hint = disconnected
+ ? '网络已断开,轻触重试'
+ : cardBlocked
+ ? '校园卡状态异常'
+ : payment.phase == PaymentCodePhase.refreshing
+ ? '正在刷新…'
+ : '轻触二维码刷新';
+
+ return GlancePaymentCard(
+ payload: frame.qrPayload,
+ binaryPayload: frame.rawQrCode.startsWith('5638'),
+ statusLabel: '在线付款码',
+ balanceText: balance,
+ hint: hint,
+ countdown: PaymentCodeCountdown(
+ generation: payment.generation,
+ active: _entered,
+ style: TextStyle(
+ fontSize: 10,
+ color: GpTokens.campusRed.withValues(alpha: 0.62),
+ ),
+ ),
+ onTap: () => unawaited(_refresh()),
+ );
+ }
+
+ Future _retry() async {
+ if (!_entered) {
+ await ref
+ .read(paymentCodeControllerProvider.notifier)
+ .enter(online: true);
+ } else {
+ await ref.read(paymentCodeControllerProvider.notifier).refresh();
+ }
+ }
+
+ Future _refresh() async {
+ if (!_entered) return;
+ await ref.read(paymentCodeControllerProvider.notifier).refresh();
+ }
+}
+
+class _PaymentSuccess extends StatelessWidget {
+ const _PaymentSuccess({required this.result});
+
+ final TransactionResult result;
+
+ @override
+ Widget build(BuildContext context) {
+ final scheme = Theme.of(context).colorScheme;
+ return Container(
+ decoration: BoxDecoration(
+ color: GpTokens.cardCanvas,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ padding: const EdgeInsets.all(16),
+ child: Center(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(Icons.check_circle, size: 44, color: scheme.tertiary),
+ const SizedBox(height: 8),
+ const Text(
+ '支付成功',
+ style: TextStyle(
+ fontSize: 17,
+ fontWeight: FontWeight.w700,
+ color: GpTokens.campusRed,
+ ),
+ ),
+ const SizedBox(height: 4),
+ Text(
+ formatMoneyFen(result.amount.value, fixedDecimals: true),
+ style: const TextStyle(
+ fontSize: 22,
+ fontWeight: FontWeight.w700,
+ color: GpTokens.campusRed,
+ fontFeatures: [FontFeature.tabularFigures()],
+ ),
+ ),
+ if (result.merchantName != null) ...[
+ const SizedBox(height: 3),
+ Text(
+ result.merchantName!,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10,
+ color: GpTokens.campusRed.withValues(alpha: 0.62),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/features/glance/presentation/glance_shell.dart b/lib/features/glance/presentation/glance_shell.dart
new file mode 100644
index 00000000..7f98815e
--- /dev/null
+++ b/lib/features/glance/presentation/glance_shell.dart
@@ -0,0 +1,464 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+
+import '../../../models/screen_form_factor.dart';
+import '../../../services/glance_settings_service.dart';
+import '../domain/glance_snapshot.dart';
+import 'cover_glance_layout.dart';
+import 'glance_formatters.dart';
+import 'glance_widgets.dart';
+import 'rear_glance_layout.dart';
+
+/// The compact surface shown on the rear screen or the MIX Flip cover.
+///
+/// This widget is presentation-only: the live wrapper feeds it a snapshot and
+/// the host supplies the payment page, so the same layout can be rendered in
+/// tests and in the settings preview without touching services.
+class GlanceShell extends StatefulWidget {
+ const GlanceShell({
+ super.key,
+ required this.surface,
+ required this.snapshot,
+ required this.sections,
+ this.paymentBuilder,
+ this.initialSection,
+ this.requestedSection,
+ this.requestRevision = 0,
+ this.onPageChanged,
+ this.onRefresh,
+ });
+
+ final GlanceSurface surface;
+ final GlanceSnapshot snapshot;
+ final List sections;
+ final WidgetBuilder? paymentBuilder;
+ final GlanceSection? initialSection;
+ final GlanceSection? requestedSection;
+ final int requestRevision;
+ final ValueChanged? onPageChanged;
+ final VoidCallback? onRefresh;
+
+ @override
+ State createState() => _GlanceShellState();
+}
+
+class _GlanceShellState extends State {
+ late PageController _controller;
+ late int _index;
+
+ List get _sections => [
+ for (final section in widget.sections)
+ if (section != GlanceSection.payment || widget.paymentBuilder != null)
+ section,
+ ];
+
+ @override
+ void initState() {
+ super.initState();
+ final sections = _sections;
+ _index = _indexOf(sections, widget.initialSection ?? widget.requestedSection);
+ _controller = PageController(initialPage: _index);
+ }
+
+ @override
+ void didUpdateWidget(GlanceShell oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ final sections = _sections;
+ if (sections.isEmpty) return;
+ if (_index >= sections.length) {
+ _index = sections.length - 1;
+ _jumpTo(_index);
+ }
+ if (widget.requestRevision != oldWidget.requestRevision &&
+ widget.requestedSection != null) {
+ final index = sections.indexOf(widget.requestedSection!);
+ if (index >= 0) {
+ _index = index;
+ _jumpTo(index);
+ }
+ }
+ }
+
+ @override
+ void dispose() {
+ _controller.dispose();
+ super.dispose();
+ }
+
+ static int _indexOf(List sections, GlanceSection? section) {
+ if (sections.isEmpty) return 0;
+ final index = section == null ? -1 : sections.indexOf(section);
+ return index < 0 ? 0 : index;
+ }
+
+ void _jumpTo(int index) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (!mounted || !_controller.hasClients) return;
+ if (_controller.page?.round() == index) return;
+ _controller.jumpToPage(index);
+ });
+ }
+
+ void _select(int index) {
+ if (index == _index) return;
+ if (_controller.hasClients) {
+ unawaited(
+ _controller.animateToPage(
+ index,
+ duration: const Duration(milliseconds: 180),
+ curve: Curves.easeOutCubic,
+ ),
+ );
+ } else {
+ setState(() => _index = index);
+ }
+ }
+
+ String _sectionLabel(GlanceSection section) => switch (section) {
+ GlanceSection.courses => '课程',
+ GlanceSection.assignments => '作业',
+ GlanceSection.payment => '消费码',
+ };
+
+ Widget _page(BuildContext context, GlanceSection section, bool compact) {
+ final onRetry = widget.onRefresh;
+ return switch (section) {
+ GlanceSection.courses => compact
+ ? RearCoursesPage(snapshot: widget.snapshot, onRetry: onRetry)
+ : CoverCoursesPage(snapshot: widget.snapshot, onRetry: onRetry),
+ GlanceSection.assignments => compact
+ ? RearAssignmentsPage(snapshot: widget.snapshot, onRetry: onRetry)
+ : CoverAssignmentsPage(snapshot: widget.snapshot, onRetry: onRetry),
+ GlanceSection.payment => Padding(
+ padding: EdgeInsets.fromLTRB(
+ compact ? 10 : 14,
+ compact ? 2 : 4,
+ compact ? 10 : 14,
+ compact ? 2 : 6,
+ ),
+ child: widget.paymentBuilder!(context),
+ ),
+ };
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = Theme.of(context);
+ final background = theme.scaffoldBackgroundColor;
+ final dark = theme.brightness == Brightness.dark;
+ final overlay = SystemUiOverlayStyle(
+ statusBarColor: Colors.transparent,
+ statusBarIconBrightness: dark ? Brightness.light : Brightness.dark,
+ statusBarBrightness: dark ? Brightness.dark : Brightness.light,
+ systemNavigationBarColor: background,
+ systemNavigationBarDividerColor: Colors.transparent,
+ systemNavigationBarIconBrightness:
+ dark ? Brightness.light : Brightness.dark,
+ systemNavigationBarContrastEnforced: false,
+ );
+
+ return AnnotatedRegion(
+ value: overlay,
+ child: Scaffold(
+ backgroundColor: background,
+ body: SafeArea(
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final sections = _sections;
+ if (sections.isEmpty) {
+ return const GlanceMessage(
+ icon: Icons.dashboard_customize_outlined,
+ title: '未选择显示内容',
+ subtitle: '请在完整 App 的“背屏与小屏”中开启至少一项',
+ );
+ }
+ final compact = widget.surface == GlanceSurface.rear &&
+ constraints.maxWidth > constraints.maxHeight;
+ final wide = widget.surface == GlanceSurface.cover;
+ final selectedIndex = _index.clamp(0, sections.length - 1);
+ final section = sections[selectedIndex];
+ return Column(
+ children: [
+ _GlanceHeader(
+ now: widget.snapshot.now,
+ week: widget.snapshot.week,
+ inTerm: widget.snapshot.inTerm,
+ sectionLabel: _sectionLabel(section),
+ compact: compact,
+ wide: wide,
+ onRefresh: widget.onRefresh,
+ ),
+ Expanded(
+ child: PageView.builder(
+ controller: _controller,
+ itemCount: sections.length,
+ onPageChanged: (index) {
+ setState(() => _index = index);
+ widget.onPageChanged?.call(sections[index]);
+ },
+ itemBuilder: (context, index) => TickerMode(
+ enabled: index == selectedIndex,
+ child: _page(context, sections[index], compact),
+ ),
+ ),
+ ),
+ _GlanceTabs(
+ sections: sections,
+ selectedIndex: selectedIndex,
+ compact: compact,
+ labelOf: _sectionLabel,
+ onSelected: _select,
+ ),
+ ],
+ );
+ },
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _GlanceHeader extends StatelessWidget {
+ const _GlanceHeader({
+ required this.now,
+ required this.week,
+ required this.inTerm,
+ required this.sectionLabel,
+ required this.compact,
+ required this.wide,
+ this.onRefresh,
+ });
+
+ final DateTime now;
+ final int? week;
+ final bool inTerm;
+ final String sectionLabel;
+ final bool compact;
+ final bool wide;
+ final VoidCallback? onRefresh;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = Theme.of(context).colorScheme;
+ final date = formatGlanceDateLine(
+ now: now,
+ week: week,
+ inTerm: inTerm,
+ );
+ if (compact) {
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(10, 1, 10, 1),
+ child: Row(
+ children: [
+ Text(
+ formatGlanceClock(now),
+ style: TextStyle(
+ fontSize: 14,
+ fontWeight: FontWeight.w700,
+ color: colors.onSurface,
+ ),
+ ),
+ const SizedBox(width: 6),
+ Expanded(
+ child: Text(
+ date,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 9,
+ color: colors.onSurfaceVariant,
+ ),
+ ),
+ ),
+ Text(
+ sectionLabel,
+ style: TextStyle(
+ fontSize: 10,
+ fontWeight: FontWeight.w600,
+ color: colors.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+ if (wide) {
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(16, 8, 8, 2),
+ child: Row(
+ children: [
+ Text(
+ formatGlanceClock(now),
+ style: TextStyle(
+ fontSize: 24,
+ height: 1,
+ fontWeight: FontWeight.w700,
+ color: colors.onSurface,
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Text(
+ date,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 11,
+ color: colors.onSurfaceVariant,
+ ),
+ ),
+ ),
+ const SizedBox(width: 10),
+ Text(
+ sectionLabel,
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 11,
+ fontWeight: FontWeight.w600,
+ color: colors.onSurface,
+ ),
+ ),
+ if (onRefresh != null)
+ _GlanceRefreshButton(onRefresh: onRefresh!),
+ ],
+ ),
+ );
+ }
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(14, 8, 8, 3),
+ child: Row(
+ children: [
+ Text(
+ formatGlanceClock(now),
+ style: TextStyle(
+ fontSize: 22,
+ height: 1,
+ fontWeight: FontWeight.w700,
+ color: colors.onSurface,
+ ),
+ ),
+ const SizedBox(width: 9),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ date,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10,
+ color: colors.onSurfaceVariant,
+ ),
+ ),
+ Text(
+ sectionLabel,
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 11,
+ fontWeight: FontWeight.w600,
+ color: colors.onSurface,
+ ),
+ ),
+ ],
+ ),
+ ),
+ if (onRefresh != null)
+ _GlanceRefreshButton(onRefresh: onRefresh!),
+ ],
+ ),
+ );
+ }
+}
+
+class _GlanceRefreshButton extends StatelessWidget {
+ const _GlanceRefreshButton({required this.onRefresh});
+
+ final VoidCallback onRefresh;
+
+ @override
+ Widget build(BuildContext context) {
+ return Semantics(
+ label: '刷新',
+ button: true,
+ child: IconButton(
+ onPressed: onRefresh,
+ icon: const Icon(Icons.refresh, size: 18),
+ padding: EdgeInsets.zero,
+ constraints: const BoxConstraints.tightFor(
+ width: 32,
+ height: 32,
+ ),
+ visualDensity: VisualDensity.compact,
+ ),
+ );
+ }
+}
+
+class _GlanceTabs extends StatelessWidget {
+ const _GlanceTabs({
+ required this.sections,
+ required this.selectedIndex,
+ required this.compact,
+ required this.labelOf,
+ required this.onSelected,
+ });
+
+ final List sections;
+ final int selectedIndex;
+ final bool compact;
+ final String Function(GlanceSection section) labelOf;
+ final ValueChanged onSelected;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = Theme.of(context).colorScheme;
+ return Padding(
+ padding: EdgeInsets.fromLTRB(8, compact ? 1 : 3, 8, compact ? 2 : 5),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ for (var index = 0; index < sections.length; index++)
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 3),
+ child: Semantics(
+ selected: index == selectedIndex,
+ button: true,
+ child: Material(
+ color: index == selectedIndex
+ ? colors.primary
+ : Colors.transparent,
+ borderRadius: BorderRadius.circular(999),
+ child: InkWell(
+ onTap: () => onSelected(index),
+ borderRadius: BorderRadius.circular(999),
+ child: Padding(
+ padding: EdgeInsets.symmetric(
+ horizontal: compact ? 8 : 11,
+ vertical: compact ? 3 : 5,
+ ),
+ child: Text(
+ labelOf(sections[index]),
+ style: TextStyle(
+ fontSize: compact ? 9 : 11,
+ fontWeight: index == selectedIndex
+ ? FontWeight.w600
+ : FontWeight.w500,
+ color: index == selectedIndex
+ ? colors.onPrimary
+ : colors.onSurfaceVariant,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/lib/features/glance/presentation/glance_widgets.dart b/lib/features/glance/presentation/glance_widgets.dart
new file mode 100644
index 00000000..1c3290db
--- /dev/null
+++ b/lib/features/glance/presentation/glance_widgets.dart
@@ -0,0 +1,164 @@
+import 'package:flutter/material.dart';
+
+import '../domain/glance_snapshot.dart';
+
+class GlanceMessage extends StatelessWidget {
+ const GlanceMessage({
+ super.key,
+ required this.icon,
+ required this.title,
+ this.subtitle,
+ this.compact = false,
+ this.action,
+ });
+
+ final IconData icon;
+ final String title;
+ final String? subtitle;
+ final bool compact;
+ final Widget? action;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = Theme.of(context).colorScheme;
+ return Center(
+ child: Padding(
+ padding: EdgeInsets.symmetric(
+ horizontal: compact ? 12 : 24,
+ vertical: compact ? 6 : 16,
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(
+ icon,
+ size: compact ? 20 : 30,
+ color: colors.onSurfaceVariant,
+ ),
+ SizedBox(height: compact ? 4 : 10),
+ Text(
+ title,
+ textAlign: TextAlign.center,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: compact ? 12 : 14,
+ fontWeight: FontWeight.w600,
+ color: colors.onSurface,
+ ),
+ ),
+ if (subtitle != null) ...[
+ SizedBox(height: compact ? 2 : 6),
+ Text(
+ subtitle!,
+ textAlign: TextAlign.center,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: compact ? 10 : 12,
+ color: colors.onSurfaceVariant,
+ ),
+ ),
+ ],
+ if (action != null) ...[
+ SizedBox(height: compact ? 2 : 8),
+ action!,
+ ],
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class GlanceLoading extends StatelessWidget {
+ const GlanceLoading({super.key, required this.label, this.compact = false});
+
+ final String label;
+ final bool compact;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = Theme.of(context).colorScheme;
+ return Center(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox.square(
+ dimension: compact ? 18 : 24,
+ child: CircularProgressIndicator(
+ strokeWidth: 2,
+ color: colors.primary,
+ ),
+ ),
+ SizedBox(height: compact ? 6 : 10),
+ Text(
+ label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: compact ? 10 : 12,
+ color: colors.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+/// Shared empty/loading/error decision for the course and deadline pages.
+Widget? glanceUnavailableState(
+ GlanceSnapshot snapshot, {
+ required bool courses,
+ required bool compact,
+ VoidCallback? onRetry,
+}) {
+ final hasData = courses ? snapshot.hasCourses : snapshot.hasPending;
+ final loading = courses ? snapshot.scheduleLoading : snapshot.assignmentsLoading;
+ final error = courses ? snapshot.scheduleError : snapshot.assignmentsError;
+ if (hasData) return null;
+
+ Widget action() => TextButton(
+ onPressed: onRetry,
+ style: TextButton.styleFrom(
+ minimumSize: Size(compact ? 32 : 44, compact ? 24 : 32),
+ padding: EdgeInsets.symmetric(horizontal: compact ? 6 : 12),
+ tapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ visualDensity: VisualDensity.compact,
+ ),
+ child: Text(
+ '重试',
+ style: TextStyle(fontSize: compact ? 10 : 12),
+ ),
+ );
+
+ if (!snapshot.loggedIn) {
+ return GlanceMessage(
+ icon: Icons.login,
+ title: '请先在完整 App 登录',
+ subtitle: '登录后这里会显示${courses ? '今日课程' : '待办作业'}',
+ compact: compact,
+ );
+ }
+ if (loading) {
+ return GlanceLoading(
+ label: courses ? '正在加载课程…' : '正在加载待办…',
+ compact: compact,
+ );
+ }
+ if (error != null) {
+ return GlanceMessage(
+ icon: Icons.cloud_off_outlined,
+ title: courses ? '课程加载失败' : '待办加载失败',
+ subtitle: error,
+ compact: compact,
+ action: onRetry == null ? null : action(),
+ );
+ }
+ return GlanceMessage(
+ icon: courses ? Icons.free_breakfast_outlined : Icons.task_alt,
+ title: courses ? '今天没有课程' : '没有待办事项',
+ compact: compact,
+ );
+}
diff --git a/lib/features/glance/presentation/live_glance_shell.dart b/lib/features/glance/presentation/live_glance_shell.dart
new file mode 100644
index 00000000..a5ca8197
--- /dev/null
+++ b/lib/features/glance/presentation/live_glance_shell.dart
@@ -0,0 +1,134 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+
+import '../../../models/custom_course.dart';
+import '../../../models/screen_form_factor.dart';
+import '../../../services/assignment_service.dart';
+import '../../../services/auth_service.dart';
+import '../../../services/glance_settings_service.dart';
+import '../../../services/schedule_service.dart';
+import '../../../widgets/app_shell/app_entry_notifier.dart';
+import '../application/glance_snapshot_builder.dart';
+import 'glance_shell.dart';
+
+/// Wires the live services into the presentation-only [GlanceShell].
+class LiveGlanceShell extends StatefulWidget {
+ const LiveGlanceShell({
+ super.key,
+ required this.surface,
+ required this.settings,
+ required this.scheduleService,
+ required this.assignmentService,
+ required this.authService,
+ this.paymentBuilder,
+ this.consumeEntry = true,
+ });
+
+ final GlanceSurface surface;
+ final GlanceSettings settings;
+ final ScheduleService scheduleService;
+ final AssignmentService assignmentService;
+ final AuthService authService;
+ final WidgetBuilder? paymentBuilder;
+ final bool consumeEntry;
+
+ @override
+ State createState() => _LiveGlanceShellState();
+}
+
+class _LiveGlanceShellState extends State {
+ Timer? _ticker;
+ bool _tickerEnabled = true;
+ GlanceSection? _requested;
+ int _requestRevision = 0;
+
+ @override
+ void initState() {
+ super.initState();
+ appShellPendingEcardEntry.addListener(_consumeEntry);
+ _ticker = Timer.periodic(const Duration(minutes: 1), (_) {
+ if (mounted) setState(() {});
+ });
+ WidgetsBinding.instance.addPostFrameCallback((_) => _consumeEntry());
+ }
+
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ _tickerEnabled = TickerMode.valuesOf(context).enabled;
+ }
+
+ @override
+ void dispose() {
+ appShellPendingEcardEntry.removeListener(_consumeEntry);
+ _ticker?.cancel();
+ super.dispose();
+ }
+
+ void _consumeEntry() {
+ if (!widget.consumeEntry || !mounted || !_tickerEnabled) return;
+ final entry = appShellPendingEcardEntry.value;
+ if (entry == null) return;
+ appShellPendingEcardEntry.value = null;
+ if (widget.paymentBuilder == null ||
+ !widget.settings.isEnabled(GlanceSection.payment)) {
+ return;
+ }
+ setState(() {
+ _requested = GlanceSection.payment;
+ _requestRevision++;
+ });
+ }
+
+ void _refresh() {
+ widget.scheduleService.requestFetch(force: true);
+ unawaited(widget.assignmentService.fetchAssignments());
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return ListenableBuilder(
+ listenable: Listenable.merge([
+ widget.scheduleService,
+ widget.assignmentService,
+ widget.authService,
+ ]),
+ builder: (context, _) {
+ final schedule = widget.scheduleService;
+ final assignments = widget.assignmentService;
+ final now = DateTime.now();
+ final week =
+ teachingWeekOf(now, schedule.termBegin) ?? schedule.currentWeek();
+ final pending = assignments.visibleAssignments
+ .where((item) => !assignments.isCompleted(item) && item.due.isAfter(now))
+ .toList();
+ final snapshot = GlanceSnapshotBuilder.build(
+ courseTable: schedule.courseTable,
+ customCourses: schedule.customCourses,
+ termBegin: schedule.termBegin,
+ week: week,
+ rawAssignments: assignments.assignments,
+ pendingAssignments: pending,
+ semesterId: schedule.selectedSemesterId,
+ now: now,
+ loggedIn: widget.authService.isLoggedIn,
+ inTerm: schedule.isTodayInTerm,
+ scheduleLoading: schedule.loading,
+ scheduleError: schedule.error,
+ assignmentsLoading: assignments.loading,
+ assignmentsError: assignments.error,
+ );
+ return GlanceShell(
+ surface: widget.surface,
+ snapshot: snapshot,
+ sections: widget.settings.sections,
+ paymentBuilder: widget.paymentBuilder,
+ requestedSection: _requested,
+ requestRevision: _requestRevision,
+ onRefresh: _refresh,
+ );
+ },
+ );
+ }
+}
diff --git a/lib/features/glance/presentation/rear_glance_layout.dart b/lib/features/glance/presentation/rear_glance_layout.dart
new file mode 100644
index 00000000..62fe3b08
--- /dev/null
+++ b/lib/features/glance/presentation/rear_glance_layout.dart
@@ -0,0 +1,269 @@
+import 'package:flutter/material.dart';
+
+import '../../../models/course.dart';
+import '../domain/glance_snapshot.dart';
+import 'glance_formatters.dart';
+import 'glance_widgets.dart';
+
+class RearCoursesPage extends StatelessWidget {
+ const RearCoursesPage({
+ super.key,
+ required this.snapshot,
+ this.onRetry,
+ });
+
+ final GlanceSnapshot snapshot;
+ final VoidCallback? onRetry;
+
+ @override
+ Widget build(BuildContext context) {
+ final unavailable = glanceUnavailableState(
+ snapshot,
+ courses: true,
+ compact: true,
+ onRetry: onRetry,
+ );
+ if (unavailable != null) return unavailable;
+
+ final lead = snapshot.leadCourse;
+ if (lead == null) {
+ return GlanceMessage(
+ icon: Icons.nights_stay_outlined,
+ title: '今天的课已结束',
+ subtitle: '今天共 ${snapshot.courses.length} 节课',
+ compact: true,
+ );
+ }
+
+ final scheme = Theme.of(context).colorScheme;
+ final background = lead.course.color.containerColor(scheme);
+ final foreground = lead.course.color.onContainerColor(scheme);
+ final rest = snapshot.activeCourses.length - 1;
+
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(10, 2, 10, 2),
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ color: background,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(11, 7, 10, 7),
+ child: Row(
+ children: [
+ Expanded(
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(
+ _stateLabel(lead.state),
+ style: TextStyle(
+ fontSize: 10,
+ fontWeight: FontWeight.w600,
+ color: foreground.withValues(alpha: 0.78),
+ ),
+ ),
+ const SizedBox(width: 6),
+ Expanded(
+ child: Text(
+ formatGlanceCourseTime(lead.course),
+ textAlign: TextAlign.end,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10,
+ color: foreground.withValues(alpha: 0.72),
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 3),
+ Flexible(
+ child: Text(
+ lead.course.name,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 18,
+ height: 1.12,
+ fontWeight: FontWeight.w700,
+ color: foreground,
+ ),
+ ),
+ ),
+ const SizedBox(height: 2),
+ Text(
+ lead.course.location.isEmpty
+ ? '地点待定'
+ : lead.course.location,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10,
+ color: foreground.withValues(alpha: 0.78),
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(width: 8),
+ Container(
+ padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 5),
+ decoration: BoxDecoration(
+ color: foreground.withValues(alpha: 0.12),
+ borderRadius: BorderRadius.circular(8),
+ ),
+ child: Text(
+ rest > 0 ? '之后 $rest 节' : '最后一节',
+ style: TextStyle(
+ fontSize: 10,
+ fontWeight: FontWeight.w600,
+ color: foreground,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class RearAssignmentsPage extends StatelessWidget {
+ const RearAssignmentsPage({
+ super.key,
+ required this.snapshot,
+ this.onRetry,
+ });
+
+ final GlanceSnapshot snapshot;
+ final VoidCallback? onRetry;
+
+ @override
+ Widget build(BuildContext context) {
+ final unavailable = glanceUnavailableState(
+ snapshot,
+ courses: false,
+ compact: true,
+ onRetry: onRetry,
+ );
+ if (unavailable != null) return unavailable;
+
+ final item = snapshot.pendingAssignments.first;
+ final rest = snapshot.pendingAssignments.length - 1;
+ final scheme = Theme.of(context).colorScheme;
+ final urgency = _urgencyColor(item.assignment.due, snapshot.now, scheme);
+ final course = item.assignment.course;
+
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(10, 2, 10, 2),
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ color: scheme.surfaceContainerHighest.withValues(alpha: 0.55),
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(11, 7, 10, 7),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(
+ '待办',
+ style: TextStyle(
+ fontSize: 10,
+ fontWeight: FontWeight.w600,
+ color: urgency,
+ ),
+ ),
+ const Spacer(),
+ Text(
+ '${snapshot.pendingAssignments.length} 项',
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 3),
+ Flexible(
+ child: Text(
+ item.assignment.title,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 17,
+ height: 1.12,
+ fontWeight: FontWeight.w700,
+ color: scheme.onSurface,
+ ),
+ ),
+ ),
+ const SizedBox(height: 2),
+ Row(
+ children: [
+ Expanded(
+ child: Text(
+ course.isEmpty
+ ? item.assignment.kind.label
+ : '$course · ${item.assignment.kind.label}',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ),
+ const SizedBox(width: 6),
+ Text(
+ item.dueLabel,
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 11,
+ fontWeight: FontWeight.w600,
+ color: urgency,
+ ),
+ ),
+ ],
+ ),
+ if (rest > 0)
+ Text(
+ '还有 $rest 项待办',
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 10,
+ color: scheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+String _stateLabel(GlanceCourseState state) => switch (state) {
+ GlanceCourseState.ongoing => '正在上课',
+ GlanceCourseState.soon => '即将开始',
+ GlanceCourseState.upcoming => '下一节',
+ GlanceCourseState.past => '已结束',
+ };
+
+Color _urgencyColor(DateTime due, DateTime now, ColorScheme scheme) {
+ final today = DateTime(now.year, now.month, now.day);
+ final target = DateTime(due.year, due.month, due.day);
+ final days = target.difference(today).inDays;
+ if (days <= 0) return scheme.error;
+ if (days == 1) return scheme.tertiary;
+ return scheme.onSurfaceVariant;
+}
diff --git a/lib/main.dart b/lib/main.dart
index f87e697c..f5824dc5 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -19,10 +19,12 @@ import 'services/debug_logger.dart';
import 'services/ecard_bind_service.dart';
import 'services/ecard_widget_service.dart';
import 'services/egate_app_service.dart';
+import 'services/glance_settings_service.dart';
import 'services/http_client.dart';
import 'services/ids/ids_client.dart';
import 'services/oa_gym_service.dart';
import 'services/schedule_service.dart';
+import 'services/screen_form_factor_service.dart';
import 'services/service_provider.dart';
import 'services/storage_service.dart';
import 'services/sync_service.dart';
@@ -32,6 +34,7 @@ import 'services/uni_auth_service.dart';
import 'services/update_service.dart';
import 'widgets/adaptive_feedback.dart';
import 'widgets/app_shell/app_shell.dart';
+import 'widgets/glance/glance_gate.dart';
import 'widgets/privacy_consent.dart';
import 'widgets/update_dialogs.dart';
@@ -66,6 +69,8 @@ void main(List args) async {
Future _realMain(SharedPreferences prefs) async {
final storageService = StorageService(prefs);
+ final screenFormFactorService = ScreenFormFactorService();
+ final glanceSettings = GlanceSettings(storageService);
final debugLogger = DebugLogger()..enabled = storageService.debugMode;
final httpClient = LoggingHttpClient(debugLogger);
final uniAuthService = UniAuthService(logger: debugLogger);
@@ -191,6 +196,8 @@ Future _realMain(SharedPreferences prefs) async {
ecardBindService: ecardBindService,
ecardWidgetService: ecardWidgetService,
deadlineWidgetService: deadlineWidgetService,
+ screenFormFactorService: screenFormFactorService,
+ glanceSettings: glanceSettings,
),
);
@@ -324,6 +331,8 @@ class TechPieApp extends StatefulWidget {
final CampusCardService campusCardService;
final EcardBindService ecardBindService;
final EcardWidgetService? ecardWidgetService;
+ final ScreenFormFactorService? screenFormFactorService;
+ final GlanceSettings? glanceSettings;
final DeadlineWidgetService? deadlineWidgetService;
const TechPieApp({
@@ -343,6 +352,8 @@ class TechPieApp extends StatefulWidget {
required this.campusCardService,
required this.ecardBindService,
this.ecardWidgetService,
+ this.screenFormFactorService,
+ this.glanceSettings,
this.deadlineWidgetService,
});
@@ -484,19 +495,23 @@ class _TechPieAppState extends State with WidgetsBindingObserver {
campusCardService: widget.campusCardService,
ecardBindService: widget.ecardBindService,
ecardWidgetService: widget.ecardWidgetService,
+ screenFormFactorService: widget.screenFormFactorService,
+ glanceSettings: widget.glanceSettings,
child: MaterialApp(
navigatorKey: _navigatorKey,
scaffoldMessengerKey: rootMessengerKey,
navigatorObservers: [FeedbackRouteObserver(), _nativeChromeObserver],
- builder: (context, child) => AdaptiveFeedbackHost(
- key: adaptiveFeedbackHostKey,
- child: child ?? const SizedBox.shrink(),
+ builder: (context, child) => GlanceGate(
+ child: AdaptiveFeedbackHost(
+ key: adaptiveFeedbackHostKey,
+ child: child ?? const SizedBox.shrink(),
+ ),
),
title: 'TechPie',
theme: widget.themeService.lightTheme,
darkTheme: widget.themeService.darkTheme,
themeMode: widget.themeService.themeMode,
- home: const PrivacyGate(child: AppShell()),
+ home: PrivacyGate(onAccepted: () { if (mounted) setState(() {}); }, child: const AppShell()),
),
),
);
diff --git a/lib/models/screen_form_factor.dart b/lib/models/screen_form_factor.dart
new file mode 100644
index 00000000..3141052a
--- /dev/null
+++ b/lib/models/screen_form_factor.dart
@@ -0,0 +1,115 @@
+import 'package:flutter/foundation.dart';
+
+/// The kind of small surface the app is currently rendered on.
+enum GlanceSurface { none, cover, rear }
+
+/// Native description of the screen this activity is attached to.
+@immutable
+final class ScreenFormFactorInfo {
+ const ScreenFormFactorInfo({
+ required this.isFlipDevice,
+ required this.isRearDevice,
+ required this.displayId,
+ required this.windowWidthPx,
+ required this.windowHeightPx,
+ required this.density,
+ required this.densityDpi,
+ required this.isDefaultDisplay,
+ required this.isInMultiWindowMode,
+ required this.model,
+ required this.manufacturer,
+ required this.sdkInt,
+ });
+
+ factory ScreenFormFactorInfo.fromMap(Map