mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-28 13:49:15 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Flutter 3.50 deprecates package:flutter/material.dart, so the app moves to material_ui 1.11.0 together with sync_settings_ui 0.8.0 and github_device_auth 0.5.0 (crdt_sync 0.13.1 rides along). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
2.5 KiB
Dart
80 lines
2.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:wake_alarm_sync/services/home_presence.dart';
|
|
import 'package:wake_alarm_sync/ui/cues.dart';
|
|
|
|
/// One line saying what tonight's alarm will demand, and why.
|
|
///
|
|
/// This exists because an unreadable signal resolves to *away*, which
|
|
/// silently drops the two tag stages. A revoked location permission would
|
|
/// otherwise weaken the alarm with no error anywhere; here it is a sentence
|
|
/// on the home screen naming the cause.
|
|
///
|
|
/// Self-loading rather than fed from `HomeScreen`, so the screen absorbs one
|
|
/// widget and none of the state.
|
|
class HomePresenceLine extends StatefulWidget {
|
|
/// Creates the line; [presence] is injectable so tests need no platform.
|
|
const HomePresenceLine({super.key, this.presence});
|
|
|
|
/// Presence resolver; defaults to the real one.
|
|
final HomePresence? presence;
|
|
|
|
@override
|
|
State<HomePresenceLine> createState() => _HomePresenceLineState();
|
|
}
|
|
|
|
class _HomePresenceLineState extends State<HomePresenceLine> {
|
|
late final HomePresence _presence = widget.presence ?? HomePresence();
|
|
|
|
PresenceVerdict? _verdict;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
unawaited(_load());
|
|
}
|
|
|
|
Future<void> _load() async {
|
|
// Never throws by contract, but a platform-less test binding can still
|
|
// fail inside SharedPreferences before resolve() gets to catch anything.
|
|
PresenceVerdict? verdict;
|
|
try {
|
|
verdict = await _presence.resolve();
|
|
} on Object {
|
|
verdict = null;
|
|
}
|
|
if (!mounted) return;
|
|
setState(() => _verdict = verdict);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final verdict = _verdict;
|
|
if (verdict == null) return const SizedBox.shrink();
|
|
final atHome = verdict.state == PresenceState.home;
|
|
final theme = Theme.of(context);
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 12),
|
|
child: SpokenLabel(
|
|
semanticLabel: atHome
|
|
? 'Tonight: tags required — ${verdict.detail}'
|
|
: 'Tonight: tags skipped — ${verdict.detail}',
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(
|
|
atHome ? Icons.nfc : Icons.directions_walk,
|
|
size: 18,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
const SizedBox(width: 4),
|
|
Icon(atHome ? Icons.home : Icons.explore, size: 18),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|