Skip to content

Offline gym log for Android. No account, no ads, no internet.

Open today's workout from an NFC tag and add the icon picker to settings

InlitX44414e2974be
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 8ed02d3..65c563e 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
<uses-permission android:name="android.permission.VIBRATE"/>
+ <uses-permission android:name="android.permission.NFC"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
@@ -31,6 +32,7 @@
<uses-feature android:name="android.hardware.type.watch" android:required="false"/>
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
+ <uses-feature android:name="android.hardware.nfc" android:required="false"/>
<application
android:label="GymMane"
@@ -74,13 +76,6 @@
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- <meta-data
- android:name="android.app.shortcuts"
- android:resource="@xml/shortcuts"/>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
@@ -95,6 +90,193 @@
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
+ <activity-alias
+ android:name=".IconDefault"
+ android:enabled="true"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher"
+ android:roundIcon="@mipmap/ic_launcher"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconLight"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_light"
+ android:roundIcon="@mipmap/ic_launcher_light"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconSand"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_sand"
+ android:roundIcon="@mipmap/ic_launcher_sand"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconGraphite"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_graphite"
+ android:roundIcon="@mipmap/ic_launcher_graphite"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconSage"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_sage"
+ android:roundIcon="@mipmap/ic_launcher_sage"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconNight"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_night"
+ android:roundIcon="@mipmap/ic_launcher_night"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconMaterial"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_material"
+ android:roundIcon="@mipmap/ic_launcher_material"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconMedal"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_medal"
+ android:roundIcon="@mipmap/ic_launcher_medal"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconGlass"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_glass"
+ android:roundIcon="@mipmap/ic_launcher_glass"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconStopwatch"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_stopwatch"
+ android:roundIcon="@mipmap/ic_launcher_stopwatch"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".IconMarble"
+ android:enabled="false"
+ android:exported="true"
+ android:icon="@mipmap/ic_launcher_marble"
+ android:roundIcon="@mipmap/ic_launcher_marble"
+ android:label="GymMane"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts"/>
+ </activity-alias>
+ <activity-alias
+ android:name=".NfcToday"
+ android:enabled="false"
+ android:exported="true"
+ android:targetActivity=".MainActivity">
+ <intent-filter>
+ <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ <data android:scheme="gymmane" android:host="today"/>
+ </intent-filter>
+ </activity-alias>
<activity-alias
android:name=".HealthPermissionsUsage"
android:targetActivity=".MainActivity"
diff --git a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
index d2d5dd1..c10412a 100644
--- a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
@@ -170,6 +170,8 @@ class MainActivity : FlutterActivity() {
HealthBridge.attach(this, MethodChannel(messenger, HealthBridge.CHANNEL))
BackupBridge.attach(this, MethodChannel(messenger, BackupBridge.CHANNEL))
SoundBridge.attach(this, MethodChannel(messenger, SoundBridge.CHANNEL))
+ AppIconBridge.attach(this, MethodChannel(messenger, AppIconBridge.CHANNEL))
+ NfcBridge.attach(this, MethodChannel(messenger, NfcBridge.CHANNEL))
VoiceBridge.attach(this, MethodChannel(messenger, VoiceBridge.CHANNEL))
WearSurfaces.attach(this, MethodChannel(messenger, WearSurfaces.CHANNEL))
}
@@ -291,6 +293,7 @@ class MainActivity : FlutterActivity() {
override fun cleanUpFlutterEngine(flutterEngine: FlutterEngine) {
rotaryChannel = null
openChannel = null
+ NfcBridge.detach(this)
LiveNotifier.dart = null
HealthBridge.channel = null
if (isFinishing) LiveNotifier.cancel(this)
@@ -313,7 +316,18 @@ class MainActivity : FlutterActivity() {
incomingChannel?.invokeMethod("incoming", text)
}
+ override fun onResume() {
+ super.onResume()
+ NfcBridge.resume(this)
+ }
+
+ override fun onPause() {
+ NfcBridge.pause(this)
+ super.onPause()
+ }
+
private fun takeOpen(intent: Intent?): String? {
+ if (NfcBridge.isToday(intent)) return "nfc/today"
val route = intent?.getStringExtra(OPEN_EXTRA) ?: return null
intent.removeExtra(OPEN_EXTRA)
return route
@@ -321,6 +335,7 @@ class MainActivity : FlutterActivity() {
private fun takeIncoming(intent: Intent?): String? {
if (intent == null || intent.action == Intent.ACTION_VIEW_PERMISSION_USAGE) return null
+ if (intent.action == android.nfc.NfcAdapter.ACTION_NDEF_DISCOVERED) return null
val text = when (intent.action) {
Intent.ACTION_VIEW -> intent.data?.let { readText(it) }
Intent.ACTION_SEND -> streamOf(intent)?.let { readText(it) }
diff --git a/android/app/src/main/kotlin/com/gymmane/app/NfcBridge.kt b/android/app/src/main/kotlin/com/gymmane/app/NfcBridge.kt
new file mode 100644
index 0000000..277c3f7
--- /dev/null
+++ b/android/app/src/main/kotlin/com/gymmane/app/NfcBridge.kt
@@ -0,0 +1,154 @@
+package com.gymmane.app
+
+import android.app.Activity
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import android.content.pm.PackageManager
+import android.net.Uri
+import android.nfc.NdefMessage
+import android.nfc.NdefRecord
+import android.nfc.NfcAdapter
+import android.nfc.Tag
+import android.nfc.tech.Ndef
+import android.nfc.tech.NdefFormatable
+import android.os.Handler
+import android.os.Looper
+import android.provider.Settings
+import io.flutter.plugin.common.MethodChannel
+
+object NfcBridge {
+ const val CHANNEL = "gymmane/nfc"
+ private const val SCHEME = "gymmane"
+ private const val HOST = "today"
+ private const val ALIAS = "com.gymmane.app.NfcToday"
+ private var channel: MethodChannel? = null
+ @Volatile private var writing = false
+ private val main = Handler(Looper.getMainLooper())
+
+ fun attach(activity: Activity, ch: MethodChannel) {
+ channel = ch
+ ch.setMethodCallHandler { call, result ->
+ when (call.method) {
+ "state" -> {
+ val adapter = NfcAdapter.getDefaultAdapter(activity)
+ result.success(mapOf("available" to (adapter != null), "enabled" to (adapter?.isEnabled == true)))
+ }
+ "listen" -> {
+ listen(activity, call.argument<Boolean>("on") == true)
+ result.success(null)
+ }
+ "write" -> result.success(startWrite(activity))
+ "cancel" -> {
+ stopWrite(activity)
+ result.success(null)
+ }
+ "settings" -> {
+ runCatching { activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS)) }
+ .onFailure { runCatching { activity.startActivity(Intent(Settings.ACTION_WIRELESS_SETTINGS)) } }
+ result.success(null)
+ }
+ else -> result.notImplemented()
+ }
+ }
+ }
+
+ fun detach(activity: Activity) {
+ stopWrite(activity)
+ channel = null
+ }
+
+ fun resume(activity: Activity) {
+ if (writing) enableReader(activity)
+ }
+
+ fun pause(activity: Activity) {
+ runCatching { NfcAdapter.getDefaultAdapter(activity)?.disableReaderMode(activity) }
+ }
+
+ fun isToday(intent: Intent?): Boolean {
+ if (intent?.action != NfcAdapter.ACTION_NDEF_DISCOVERED) return false
+ val uri = intent.data ?: return false
+ if (uri.scheme != SCHEME || uri.host != HOST) return false
+ intent.action = Intent.ACTION_MAIN
+ intent.data = null
+ return true
+ }
+
+ private fun listen(context: Context, on: Boolean) {
+ val state = if (on) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED
+ val component = ComponentName(context.packageName, ALIAS)
+ runCatching {
+ if (context.packageManager.getComponentEnabledSetting(component) != state) {
+ context.packageManager.setComponentEnabledSetting(component, state, PackageManager.DONT_KILL_APP)
+ }
+ }
+ }
+
+ private fun startWrite(activity: Activity): Boolean {
+ val adapter = NfcAdapter.getDefaultAdapter(activity) ?: return false
+ if (!adapter.isEnabled) return false
+ writing = true
+ enableReader(activity)
+ return true
+ }
+
+ private fun stopWrite(activity: Activity) {
+ writing = false
+ pause(activity)
+ }
+
+ private fun enableReader(activity: Activity) {
+ val adapter = NfcAdapter.getDefaultAdapter(activity) ?: return
+ val flags = NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_NFC_B or
+ NfcAdapter.FLAG_READER_NFC_F or NfcAdapter.FLAG_READER_NFC_V
+ runCatching { adapter.enableReaderMode(activity, { tag -> onTag(activity, tag) }, flags, null) }
+ }
+
+ private fun message(): NdefMessage =
+ NdefMessage(arrayOf(NdefRecord.createUri(Uri.Builder().scheme(SCHEME).authority(HOST).build())))
+
+ private fun onTag(activity: Activity, tag: Tag) {
+ if (!writing) return
+ val outcome = write(tag, message())
+ if (outcome == "ok") {
+ writing = false
+ main.post { pause(activity) }
+ }
+ main.post { channel?.invokeMethod("written", outcome) }
+ }
+
+ private fun write(tag: Tag, message: NdefMessage): String {
+ val bytes = message.toByteArray()
+ Ndef.get(tag)?.let { ndef ->
+ return try {
+ ndef.connect()
+ when {
+ !ndef.isWritable -> "locked"
+ ndef.maxSize < bytes.size -> "small"
+ else -> {
+ ndef.writeNdefMessage(message)
+ val back = runCatching { ndef.ndefMessage?.toByteArray() }.getOrNull()
+ if (back == null || back.contentEquals(bytes)) "ok" else "lost"
+ }
+ }
+ } catch (_: Exception) {
+ "lost"
+ } finally {
+ runCatching { ndef.close() }
+ }
+ }
+ NdefFormatable.get(tag)?.let { blank ->
+ return try {
+ blank.connect()
+ blank.format(message)
+ "ok"
+ } catch (_: Exception) {
+ "lost"
+ } finally {
+ runCatching { blank.close() }
+ }
+ }
+ return "unsupported"
+ }
+}
diff --git a/lib/app/app_shell.dart b/lib/app/app_shell.dart
index 47b330d..99b4452 100644
--- a/lib/app/app_shell.dart
+++ b/lib/app/app_shell.dart
@@ -48,6 +48,7 @@ import '../services/supplement_reminder.dart';
import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
+import '../widgets/nfc_sheet.dart';
import '../widgets/app_background.dart';
import '../widgets/award_celebration.dart';
import '../widgets/dialogs.dart';
@@ -144,6 +145,10 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Single
}
void _openFromWidget(String route) {
+ if (route == 'nfc/today') {
+ if (mounted) openTodayFromTag(context);
+ return;
+ }
if (!mounted || !fit.onboarded || fit.isSessionActive) return;
if (route == 'play') {
playWorkout(context);
diff --git a/lib/main.dart b/lib/main.dart
index 8747538..5c50308 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -11,6 +11,8 @@ import 'services/nutrition_widgets.dart';
import 'services/live_workout.dart';
import 'services/local_store.dart';
import 'services/media_store.dart';
+import 'services/app_icon.dart';
+import 'services/nfc_tags.dart';
import 'services/graphics_mode.dart';
import 'services/rest_alarm.dart';
import 'services/screen_awake.dart';
@@ -35,7 +37,9 @@ Future<void> main() async {
await AlarmStore.init();
await RestAlarm.instance.init();
GraphicsMode.load();
+ AppIcon.load();
fit.loadFromStore();
+ NfcTags.load();
fit.syncPhotoReminder();
fit.syncMeasureReminder();
fit.syncTrainReminder();
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 5a1ad58..ec40d00 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -29,6 +29,10 @@ import '../services/workout_import.dart';
import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
+import '../services/app_icon.dart';
+import '../services/nfc_tags.dart';
+import '../widgets/app_icon_sheet.dart';
+import '../widgets/nfc_sheet.dart';
import '../widgets/auto_backup_sheet.dart';
import '../widgets/body_rulers.dart';
import '../widgets/dialogs.dart';
@@ -212,6 +216,24 @@ class SettingsScreen extends StatelessWidget {
]),
),
),
+ if (AppIcon.available)
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => showAppIconSheet(context),
+ child: _prefRow(
+ gc,
+ PhosphorIconsRegular.appWindow,
+ t.appIcon,
+ Row(mainAxisSize: MainAxisSize.min, children: [
+ ValueListenableBuilder<String>(
+ valueListenable: AppIcon.current,
+ builder: (_, _, _) => AppIconThumb(AppIcon.style, size: 26),
+ ),
+ const SizedBox(width: 8),
+ Icon(PhosphorIconsRegular.caretRight, size: 15, color: gc.textTertiary),
+ ]),
+ ),
+ ),
GestureDetector(
behavior: HitTestBehavior.opaque,
@@ -464,6 +486,23 @@ class SettingsScreen extends StatelessWidget {
hint: t.voiceSettingHint,
badge: BetaTag(t.sectionBeta, small: true)),
),
+ if (NfcTags.available)
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => showNfcSheet(context),
+ child: _prefRow(
+ gc,
+ PhosphorIconsRegular.contactlessPayment,
+ t.nfcRow,
+ Row(mainAxisSize: MainAxisSize.min, children: [
+ Text(fit.nfcTag ? t.nfcOn : t.nfcOff,
+ style: AppTheme.f(13, weight: FontWeight.w600, color: gc.textSecondary)),
+ const SizedBox(width: 6),
+ Icon(PhosphorIconsRegular.caretRight, size: 15, color: gc.textTertiary),
+ ]),
+ hint: t.nfcRowHint,
+ ),
+ ),
]),
_subhead(gc, t.routines),
_card(gc, [
@@ -840,6 +879,7 @@ class SettingsScreen extends StatelessWidget {
(t.heatRangeSetting, PhosphorIconsRegular.calendarDots),
(t.heatmapLabelsSetting, PhosphorIconsRegular.gridNine),
(t.background, PhosphorIconsRegular.image),
+ if (AppIcon.available) (t.appIcon, PhosphorIconsRegular.appWindow),
(t.perfSetting, PhosphorIconsRegular.lightning),
(t.textSizeSetting, PhosphorIconsRegular.textAa),
]),
@@ -853,6 +893,7 @@ class SettingsScreen extends StatelessWidget {
(t.autoProgressSetting, PhosphorIconsRegular.trendUp),
(t.deloadSetting, PhosphorIconsRegular.feather),
(t.voiceSetting, PhosphorIconsRegular.waveform),
+ if (NfcTags.available) (t.nfcRow, PhosphorIconsRegular.contactlessPayment),
(t.autoAdvance, PhosphorIconsRegular.skipForward),
(t.countdownSetting, PhosphorIconsRegular.timer),
(t.keepScreenOn, PhosphorIconsRegular.sun),
diff --git a/lib/services/nfc_tags.dart b/lib/services/nfc_tags.dart
new file mode 100644
index 0000000..82e91c0
--- /dev/null
+++ b/lib/services/nfc_tags.dart
@@ -0,0 +1,68 @@
+import 'dart:async';
+
+import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
+
+import '../state/fit_state.dart';
+
+class NfcTags {
+ NfcTags._();
+
+ static const _channel = MethodChannel('gymmane/nfc');
+ static final _written = StreamController<String>.broadcast();
+
+ static bool available = false;
+ static bool? _listening;
+
+ static Stream<String> get written => _written.stream;
+
+ static bool get _android => !kIsWeb && defaultTargetPlatform == TargetPlatform.android;
+
+ static Future<void> load() async {
+ if (!_android) return;
+ _channel.setMethodCallHandler((call) async {
+ if (call.method == 'written' && call.arguments is String) _written.add(call.arguments as String);
+ });
+ available = (await state()).available;
+ if (!available) return;
+ _sync();
+ fit.addListener(_sync);
+ }
+
+ static void _sync() {
+ final on = fit.nfcTag;
+ if (_listening == on) return;
+ _listening = on;
+ _channel.invokeMethod<void>('listen', {'on': on}).catchError((_) {});
+ }
+
+ static Future<({bool available, bool enabled})> state() async {
+ if (!_android) return (available: false, enabled: false);
+ try {
+ final s = await _channel.invokeMapMethod<String, Object?>('state');
+ return (available: s?['available'] == true, enabled: s?['enabled'] == true);
+ } catch (_) {
+ return (available: false, enabled: false);
+ }
+ }
+
+ static Future<bool> write() async {
+ try {
+ return await _channel.invokeMethod<bool>('write') ?? false;
+ } catch (_) {
+ return false;
+ }
+ }
+
+ static Future<void> cancel() async {
+ try {
+ await _channel.invokeMethod<void>('cancel');
+ } catch (_) {}
+ }
+
+ static Future<void> openSettings() async {
+ try {
+ await _channel.invokeMethod<void>('settings');
+ } catch (_) {}
+ }
+}
diff --git a/lib/state/fit_state.dart b/lib/state/fit_state.dart
index e883740..ee5cc9f 100644
--- a/lib/state/fit_state.dart
+++ b/lib/state/fit_state.dart
@@ -326,6 +326,7 @@ class FitState extends FitCore
askCheckIn = data['checkIn'] as bool? ?? true;
muscleTune = data['mTune'] as bool? ?? true;
voiceCoach = data['voice'] as bool? ?? false;
+ nfcTag = data['nfc'] as bool? ?? false;
final every = (data['deload'] as num?)?.toInt() ?? 0;
deloadEvery = SettingsState.deloadChoices.contains(every) ? every : 0;
deloadFrom = deloadEvery > 0 ? DateTime.tryParse((data['deloadFrom'] as String?) ?? '') ?? DateTime.now() : null;
@@ -591,6 +592,7 @@ class FitState extends FitCore
if (!askCheckIn) 'checkIn': false,
if (!muscleTune) 'mTune': false,
if (voiceCoach) 'voice': true,
+ if (nfcTag) 'nfc': true,
if (deloadEvery > 0) 'deload': deloadEvery,
if (deloadFrom != null) 'deloadFrom': deloadFrom!.toIso8601String(),
if (lowEndAsked) 'lowEndAsked': true,
diff --git a/lib/state/settings_state.dart b/lib/state/settings_state.dart
index 678540f..ee1f03e 100644
--- a/lib/state/settings_state.dart
+++ b/lib/state/settings_state.dart
@@ -60,6 +60,7 @@ mixin SettingsState on FitCore, ToolsState, LibraryState {
bool muscleTune = true;
bool voiceCoach = false;
+ bool nfcTag = false;
int deloadEvery = 0;
DateTime? deloadFrom;
static const deloadChoices = [0, 4, 5, 6, 8];
@@ -89,6 +90,13 @@ mixin SettingsState on FitCore, ToolsState, LibraryState {
notifyListeners();
}
+ void setNfcTag(bool on) {
+ if (nfcTag == on) return;
+ nfcTag = on;
+ _persist();
+ notifyListeners();
+ }
+
void toggleVoiceCoach() {
voiceCoach = !voiceCoach;
if (!voiceCoach) VoiceCoach.stop();
diff --git a/lib/widgets/nfc_sheet.dart b/lib/widgets/nfc_sheet.dart
new file mode 100644
index 0000000..63eaf1a
--- /dev/null
+++ b/lib/widgets/nfc_sheet.dart
@@ -0,0 +1,1039 @@
+import 'dart:async';
+import 'dart:math' as math;
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../models/exercise.dart';
+import '../models/workout.dart';
+import '../screens/start_sheet.dart';
+import '../services/nfc_tags.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import 'exercise_media.dart';
+import 'glass.dart';
+import 'svg_icon.dart';
+import 'ui_kit.dart';
+
+void showNfcSheet(BuildContext context) {
+ showAppSheet<void>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ builder: (_) => const _NfcSheet(),
+ );
+}
+
+DateTime? _lastTag;
+
+void openTodayFromTag(BuildContext context) {
+ if (!fit.nfcTag || !fit.onboarded || _TodaySheetState.open != null) return;
+ final now = DateTime.now();
+ final last = _lastTag;
+ if (last != null && now.difference(last) < const Duration(milliseconds: 1500)) return;
+ _lastTag = now;
+ final s = fit.session;
+ if (s != null && !s.complete) {
+ if (fit.sessionParked) {
+ HapticFeedback.mediumImpact();
+ fit.stepBackIntoSession();
+ }
+ return;
+ }
+ HapticFeedback.mediumImpact();
+ if (!fit.restingToday && _todayRoutines().isEmpty) {
+ showStartSheet(context);
+ return;
+ }
+ showAppSheet<void>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ builder: (_) => const _TodaySheet(),
+ );
+}
+
+List<Routine> _todayRoutines() => [
+ for (final r in fit.routinesOn(DateTime.now()))
+ if (r.exerciseIds.isNotEmpty) r,
+ ];
+
+class _Sticker extends StatelessWidget {
+ const _Sticker({required this.size, this.badge, this.dim = false});
+
+ final double size;
+ final Widget? badge;
+ final bool dim;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return SizedBox(
+ width: size,
+ height: size,
+ child: Stack(clipBehavior: Clip.none, children: [
+ AnimatedOpacity(
+ duration: const Duration(milliseconds: 220),
+ opacity: dim ? 0.4 : 1,
+ child: Container(
+ width: size,
+ height: size,
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ gradient: const LinearGradient(
+ begin: Alignment.topLeft,
+ end: Alignment.bottomRight,
+ colors: [Color(0xFFF0C4A6), Color(0xFFD9A184), Color(0xFFB07A5C)],
+ ),
+ border: Border.all(color: const Color(0xFFFFE6D4).withValues(alpha: 0.7), width: 1.2),
+ boxShadow: [
+ BoxShadow(color: Colors.black.withValues(alpha: 0.45), blurRadius: 18, offset: const Offset(0, 10)),
+ ],
+ ),
+ child: Stack(children: [
+ Positioned.fill(
+ child: ClipOval(
+ child: CustomPaint(painter: _ShinePainter()),
+ ),
+ ),
+ Center(
+ child: Padding(
+ padding: EdgeInsets.all(size * 0.17),
+ child: Image.asset('assets/img/runner.png',
+ color: const Color(0xFF1C1411), colorBlendMode: BlendMode.srcIn, fit: BoxFit.contain),
+ ),
+ ),
+ ]),
+ ),
+ ),
+ if (badge != null)
+ PositionedDirectional(
+ end: -2,
+ top: -2,
+ child: Container(
+ decoration: BoxDecoration(shape: BoxShape.circle, border: Border.all(color: gc.bgRaised, width: 3)),
+ child: badge,
+ ),
+ ),
+ ]),
+ );
+ }
+}
+
+class _ShinePainter extends CustomPainter {
+ @override
+ void paint(Canvas canvas, Size size) {
+ final p = Paint()
+ ..shader = LinearGradient(
+ begin: Alignment.topLeft,
+ end: Alignment.bottomRight,
+ colors: [Colors.white.withValues(alpha: 0.38), Colors.white.withValues(alpha: 0)],
+ stops: const [0, 0.55],
+ ).createShader(Offset.zero & size);
+ canvas.drawPath(
+ Path()
+ ..moveTo(0, 0)
+ ..lineTo(size.width * 0.72, 0)
+ ..lineTo(0, size.height * 0.72)
+ ..close(),
+ p,
+ );
+ }
+
+ @override
+ bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
+}
+
+class _Waves extends StatelessWidget {
+ const _Waves({required this.color, this.size = 34, this.flip = false});
+
+ final Color color;
+ final double size;
+ final bool flip;
+
+ @override
+ Widget build(BuildContext context) {
+ return Transform.flip(
+ flipX: flip,
+ child: CustomPaint(size: Size(size, size), painter: _WavesPainter(color)),
+ );
+ }
+}
+
+class _WavesPainter extends CustomPainter {
+ _WavesPainter(this.color);
+
+ final Color color;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final c = Offset(0, size.height / 2);
+ for (var i = 0; i < 3; i++) {
+ final r = size.width * (0.38 + i * 0.3);
+ canvas.drawArc(
+ Rect.fromCircle(center: c, radius: r),
+ -math.pi / 4,
+ math.pi / 2,
+ false,
+ Paint()
+ ..color = color.withValues(alpha: 0.85 - i * 0.25)
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 2.2
+ ..strokeCap = StrokeCap.round,
+ );
+ }
+ }
+
+ @override
+ bool shouldRepaint(covariant _WavesPainter old) => old.color != color;
+}
+
+const double _phoneRatio = 147.6 / 71.6;
+
+class _PhoneFrame extends StatelessWidget {
+ const _PhoneFrame({required this.width, required this.child, this.back = false});
+
+ final double width;
+ final Widget child;
+ final bool back;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final w = width;
+ final h = w * _phoneRatio;
+ final band = w * 0.028;
+ final radius = w * 0.165;
+ final inset = back ? 0.0 : w * 0.022;
+ Widget key(double top, double len, {bool right = false}) => Positioned(
+ top: top,
+ left: right ? null : -w * 0.018,
+ right: right ? -w * 0.018 : null,
+ child: Container(
+ width: w * 0.022,
+ height: len,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(w * 0.01),
+ gradient: const LinearGradient(colors: [Color(0xFF5A5652), Color(0xFF2A2826)]),
+ ),
+ ),
+ );
+ return SizedBox(
+ width: w,
+ height: h,
+ child: Stack(clipBehavior: Clip.none, children: [
+ key(h * 0.19, h * 0.06, right: back),
+ key(h * 0.28, h * 0.1, right: back),
+ key(h * 0.4, h * 0.1, right: back),
+ key(h * 0.3, h * 0.15, right: !back),
+ Container(
+ width: w,
+ height: h,
+ padding: EdgeInsets.all(band),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(radius),
+ gradient: const LinearGradient(
+ begin: Alignment.topLeft,
+ end: Alignment.bottomRight,
+ colors: [Color(0xFF8E8A85), Color(0xFF3A3734), Color(0xFF1F1D1B), Color(0xFF5C5853)],
+ stops: [0, 0.3, 0.7, 1],
+ ),
+ boxShadow: [
+ BoxShadow(color: Colors.black.withValues(alpha: 0.4), blurRadius: 22, offset: const Offset(0, 8)),
+ ],
+ ),
+ child: Container(
+ padding: EdgeInsets.all(inset),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(radius - band),
+ color: back ? null : Colors.black,
+ gradient: back
+ ? const LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [Color(0xFF2A2725), Color(0xFF1B1918), Color(0xFF141312)],
+ )
+ : null,
+ ),
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(radius - band - inset),
+ child: back ? child : ColoredBox(color: gc.bg, child: child),
+ ),
+ ),
+ ),
+ ]),
+ );
+ }
+}
+
+class _PhoneBack extends StatelessWidget {
+ const _PhoneBack({required this.width, required this.dim});
+
+ final double width;
+ final bool dim;
+
+ @override
+ Widget build(BuildContext context) {
+ final w = width;
+ Widget lens(double d) => Container(
+ width: d,
+ height: d,
+ padding: EdgeInsets.all(d * 0.09),
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ gradient: const LinearGradient(
+ begin: Alignment.topLeft,
+ end: Alignment.bottomRight,
+ colors: [Color(0xFFB9B4AE), Color(0xFF4A4642), Color(0xFF8A857F)],
+ ),
+ boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.6), blurRadius: d * 0.2, offset: Offset(0, d * 0.08))],
+ ),
+ child: Container(
+ decoration: const BoxDecoration(
+ shape: BoxShape.circle,
+ gradient: RadialGradient(
+ center: Alignment(-0.35, -0.35),
+ radius: 0.9,
+ colors: [Color(0xFF3B4A66), Color(0xFF141A26), Color(0xFF020203)],
+ stops: [0, 0.45, 1],
+ ),
+ ),
+ child: Align(
+ alignment: const Alignment(-0.38, -0.42),
+ child: Container(
+ width: d * 0.16,
+ height: d * 0.16,
+ decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.white.withValues(alpha: 0.55)),
+ ),
+ ),
+ ),
+ );
+ final module = w * 0.4;
+ return AnimatedOpacity(
+ duration: const Duration(milliseconds: 220),
+ opacity: dim ? 0.5 : 1,
+ child: _PhoneFrame(
+ width: w,
+ back: true,
+ child: Stack(children: [
+ Positioned.fill(
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: const Alignment(-1, -1),
+ end: const Alignment(0.6, 0.2),
+ colors: [Colors.white.withValues(alpha: 0.09), Colors.white.withValues(alpha: 0)],
+ ),
+ ),
+ ),
+ ),
+ Positioned(
+ left: w * 0.06,
+ top: w * 0.06,
+ child: Container(
+ width: module,
+ height: module,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(module * 0.28),
+ gradient: const LinearGradient(
+ begin: Alignment.topLeft,
+ end: Alignment.bottomRight,
+ colors: [Color(0xFF3A3633), Color(0xFF221F1D)],
+ ),
+ border: Border.all(color: Colors.white.withValues(alpha: 0.14), width: 0.8),
+ boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.5), blurRadius: 8, offset: const Offset(0, 3))],
+ ),
+ child: Stack(children: [
+ Positioned(left: module * 0.08, top: module * 0.08, child: lens(module * 0.44)),
+ Positioned(right: module * 0.08, bottom: module * 0.08, child: lens(module * 0.44)),
+ Positioned(
+ right: module * 0.15,
+ top: module * 0.15,
+ child: Container(
+ width: module * 0.15,
+ height: module * 0.15,
+ decoration: const BoxDecoration(
+ shape: BoxShape.circle,
+ gradient: RadialGradient(colors: [Color(0xFFFFF4DA), Color(0xFFCDB98F)]),
+ ),
+ ),
+ ),
+ Positioned(
+ left: module * 0.2,
+ bottom: module * 0.2,
+ child: Container(
+ width: module * 0.05,
+ height: module * 0.05,
+ decoration: const BoxDecoration(shape: BoxShape.circle, color: Color(0xFF0C0B0A)),
+ ),
+ ),
+ ]),
+ ),
+ ),
+ Center(
+ child: Image.asset('assets/img/runner.png',
+ height: w * 0.3, color: Colors.white.withValues(alpha: 0.2), colorBlendMode: BlendMode.srcIn),
+ ),
+ ]),
+ ),
+ );
+ }
+}
+
+class _NfcTag extends StatelessWidget {
+ const _NfcTag();
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Container(
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
+ decoration: BoxDecoration(
+ color: gc.accent.withValues(alpha: 0.14),
+ borderRadius: BorderRadius.circular(8),
+ border: Border.all(color: gc.accent.withValues(alpha: 0.45)),
+ ),
+ child: Text('NFC', style: AppTheme.f(10, weight: FontWeight.w800, color: gc.accent, letterSpacing: 1.2)),
+ );
+ }
+}
+
+class _ScreenPreview extends StatelessWidget {
+ const _ScreenPreview({required this.width});
+
+ final double width;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final s = width / 140;
+ final resting = fit.restingToday;
+ final list = _todayRoutines();
+ final pending = fit.pendingRoutinesOn(DateTime.now()).where((r) => r.exerciseIds.isNotEmpty).toList();
+ final routine = pending.isNotEmpty ? pending.first : (list.isEmpty ? null : list.last);
+ final exercises = routine == null || resting ? const <Exercise>[] : fit.routineExercises(routine).take(3).toList();
+ final bar = gc.text.withValues(alpha: 0.14);
+ final faint = gc.text.withValues(alpha: 0.08);
+ Widget line(double w, double h, Color c) =>
+ Container(width: w, height: h, decoration: BoxDecoration(color: c, borderRadius: BorderRadius.circular(h)));
+ return Padding(
+ padding: EdgeInsets.fromLTRB(11 * s, 9 * s, 11 * s, 0),
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Center(
+ child: Container(
+ width: 34 * s,
+ height: 9 * s,
+ decoration: BoxDecoration(color: Colors.black, borderRadius: BorderRadius.circular(6 * s)),
+ ),
+ ),
+ SizedBox(height: 13 * s),
+ Container(
+ padding: EdgeInsets.all(10 * s),
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(14 * s)),
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Row(children: [
+ if (resting) ...[
+ Icon(PhosphorIconsFill.bed, size: 9 * s, color: gc.sage),
+ SizedBox(width: 4 * s),
+ ],
+ line(34 * s, 4 * s, faint),
+ ]),
+ SizedBox(height: 7 * s),
+ line(62 * s, 9 * s, bar),
+ SizedBox(height: 5 * s),
+ line(40 * s, 4 * s, faint),
+ SizedBox(height: 10 * s),
+ Container(
+ height: 20 * s,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ color: resting ? gc.bgRaised2 : gc.text,
+ borderRadius: BorderRadius.circular(10 * s),
+ ),
+ child: Icon(PhosphorIconsFill.play, size: 8 * s, color: resting ? gc.text : gc.bg),
+ ),
+ ]),
+ ),
+ SizedBox(height: 8 * s),
+ for (var i = 0; i < 3; i++)
+ Container(
+ margin: EdgeInsets.only(bottom: 5 * s),
+ padding: EdgeInsets.all(5 * s),
+ decoration: BoxDecoration(
+ color: resting ? gc.bgRaised.withValues(alpha: 0.6) : gc.bgRaised,
+ borderRadius: BorderRadius.circular(10 * s),
+ ),
+ child: Row(children: [
+ SizedBox(
+ width: 18 * s,
+ height: 18 * s,
+ child: i < exercises.length
+ ? ExerciseMedia(ex: exercises[i], height: 18 * s, radius: 5 * s, bordered: false)
+ : DecoratedBox(
+ decoration: BoxDecoration(color: faint, borderRadius: BorderRadius.circular(5 * s)),
+ ),
+ ),
+ SizedBox(width: 7 * s),
+ Expanded(
+ child: Align(
+ alignment: AlignmentDirectional.centerStart,
+ child: line([46.0, 58.0, 38.0][i] * s, 5 * s, i < exercises.length ? bar : faint),
+ ),
+ ),
+ ]),
+ ),
+ ]),
+ );
+ }
+}
+
+class _Hero extends StatelessWidget {
+ const _Hero();
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Container(
+ height: 214,
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(24)),
+ clipBehavior: Clip.antiAlias,
+ child: LayoutBuilder(builder: (context, box) {
+ const phone = 132.0;
+ final left = (box.maxWidth - phone) / 2 - 34;
+ return Stack(clipBehavior: Clip.hardEdge, children: [
+ Positioned(
+ left: left,
+ top: 24,
+ child: const _PhoneFrame(width: phone, child: _ScreenPreview(width: phone * 0.9)),
+ ),
+ Positioned(
+ left: left + phone + 16,
+ top: 54,
+ child: const _NfcTag(),
+ ),
+ Positioned(
+ left: left + phone + 12,
+ top: 92,
+ child: _Waves(color: gc.accent, size: 30, flip: true),
+ ),
+ Positioned(
+ left: left + phone + 48,
+ top: 76,
+ child: const _Sticker(size: 64),
+ ),
+ ]);
+ }),
+ );
+ }
+}
+
+enum _Step { intro, checking, off, waiting, done, failed }
+
+class _NfcSheet extends StatefulWidget {
+ const _NfcSheet();
+
+ @override
+ State<_NfcSheet> createState() => _NfcSheetState();
+}
+
+class _NfcSheetState extends State<_NfcSheet> with WidgetsBindingObserver {
+ _Step _step = _Step.intro;
+ String _error = '';
+ int _shake = 0;
+ StreamSubscription<String>? _sub;
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addObserver(this);
+ _sub = NfcTags.written.listen(_onWritten);
+ }
+
+ @override
+ void dispose() {
+ WidgetsBinding.instance.removeObserver(this);
+ _sub?.cancel();
+ NfcTags.cancel();
+ super.dispose();
+ }
+
+ @override
+ void didChangeAppLifecycleState(AppLifecycleState state) {
+ if (state == AppLifecycleState.resumed && _step == _Step.off) _start();
+ }
+
+ Future<void> _start() async {
+ setState(() => _step = _Step.checking);
+ final s = await NfcTags.state();
+ if (!mounted) return;
+ if (!s.enabled) {
+ setState(() => _step = _Step.off);
+ return;
+ }
+ final ok = await NfcTags.write();
+ if (!mounted) return;
+ setState(() => _step = ok ? _Step.waiting : _Step.off);
+ }
+
+ void _back() {
+ NfcTags.cancel();
+ setState(() => _step = _Step.intro);
+ }
+
+ void _onWritten(String outcome) {
+ if (!mounted || _step != _Step.waiting) return;
+ if (outcome == 'ok') {
+ HapticFeedback.mediumImpact();
+ fit.setNfcTag(true);
+ setState(() => _step = _Step.done);
+ return;
+ }
+ HapticFeedback.heavyImpact();
+ setState(() {
+ _step = _Step.failed;
+ _shake++;
+ _error = switch (outcome) {
+ 'locked' => t.nfcErrLocked,
+ 'small' => t.nfcErrSmall,
+ 'unsupported' => t.nfcErrUnsupported,
+ _ => t.nfcErrLost,
+ };
+ });
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final intro = _step == _Step.intro;
+ return Container(
+ padding: sheetPad(context),
+ constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(context).height * 0.92),
+ decoration: sheetDecoration(gc),
+ child: SingleChildScrollView(
+ child: AnimatedSize(
+ duration: const Duration(milliseconds: 280),
+ curve: Curves.easeOutCubic,
+ alignment: Alignment.topCenter,
+ child: AnimatedSwitcher(
+ duration: const Duration(milliseconds: 220),
+ layoutBuilder: (current, previous) => Stack(
+ alignment: Alignment.topCenter,
+ children: [
+ ...previous.map((w) => Positioned(left: 0, right: 0, top: 0, child: w)),
+ ?current,
+ ],
+ ),
+ child: KeyedSubtree(
+ key: ValueKey(intro),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const SheetHandle(),
+ const SizedBox(height: 16),
+ if (intro) ..._intro(context, gc) else ..._writing(context, gc),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ List<Widget> _intro(BuildContext context, GymColors gc) {
+ return [
+ SheetTitle(t.nfcTitle, subtitle: t.nfcSubtitle),
+ const SizedBox(height: 18),
+ const _Hero(),
+ const SizedBox(height: 12),
+ Container(
+ padding: const EdgeInsets.fromLTRB(16, 4, 16, 4),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(20)),
+ child: Column(children: [
+ _Point(icon: PhosphorIconsRegular.calendarCheck, title: t.nfcPoint1, body: t.nfcPoint1Body),
+ _Point(icon: PhosphorIconsRegular.bed, title: t.nfcPoint2, body: t.nfcPoint2Body),
+ _Point(icon: PhosphorIconsRegular.arrowsClockwise, title: t.nfcPoint3, body: t.nfcPoint3Body),
+ ]),
+ ),
+ const SizedBox(height: 12),
+ AnimatedBuilder(
+ animation: fit,
+ builder: (context, _) => Semantics(
+ toggled: fit.nfcTag,
+ child: Pressable(
+ onTap: () {
+ HapticFeedback.selectionClick();
+ fit.setNfcTag(!fit.nfcTag);
+ },
+ child: Container(
+ constraints: const BoxConstraints(minHeight: 58),
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(20)),
+ child: Row(children: [
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(t.nfcUse, style: AppTheme.f(14.5, weight: FontWeight.w600, color: gc.text)),
+ const SizedBox(height: 3),
+ Text(t.nfcUseHint,
+ style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textSecondary, height: 1.3)),
+ ]),
+ ),
+ const SizedBox(width: 12),
+ TinySwitch(on: fit.nfcTag),
+ ]),
+ ),
+ ),
+ ),
+ ),
+ const SizedBox(height: 20),
+ PrimaryButton(label: t.nfcWrite, onTap: _start),
+ const SizedBox(height: 10),
+ Text(t.nfcTip,
+ textAlign: TextAlign.center,
+ style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary, height: 1.4)),
+ ];
+ }
+
+ List<Widget> _writing(BuildContext context, GymColors gc) {
+ final (title, body) = switch (_step) {
+ _Step.off => (t.nfcOffTitle, t.nfcOffBody),
+ _Step.done => (t.nfcDoneTitle, t.nfcDoneBody),
+ _Step.failed => (t.nfcFailTitle, _error),
+ _ => (t.nfcWaitTitle, t.nfcWaitBody),
+ };
+ return [
+ const SizedBox(height: 6),
+ Center(child: _WritePicture(step: _step, shake: _shake)),
+ const SizedBox(height: 24),
+ AnimatedSwitcher(
+ duration: const Duration(milliseconds: 220),
+ child: Column(
+ key: ValueKey(_step == _Step.checking ? _Step.waiting : _step),
+ children: [
+ Text(title,
+ textAlign: TextAlign.center,
+ style: AppTheme.f(20, weight: FontWeight.w800, color: gc.text, height: 1.2)),
+ const SizedBox(height: 8),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 8),
+ child: Text(body,
+ textAlign: TextAlign.center,
+ style: AppTheme.f(13.5, weight: FontWeight.w500, color: gc.textSecondary, height: 1.45)),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 24),
+ ...switch (_step) {
+ _Step.off => [
+ PrimaryButton(label: t.nfcOpenSettings, onTap: NfcTags.openSettings),
+ _TextAction(label: t.cancel, onTap: _back),
+ ],
+ _Step.done => [PrimaryButton(label: t.done, onTap: () => Navigator.of(context).pop())],
+ _Step.failed => [
+ PrimaryButton(label: t.nfcRetry, onTap: _start),
+ _TextAction(label: t.cancel, onTap: _back),
+ ],
+ _ => [_TextAction(label: t.cancel, onTap: _back)],
+ },
+ ];
+ }
+}
+
+class _TextAction extends StatelessWidget {
+ const _TextAction({required this.label, required this.onTap});
+
+ final String label;
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ return Semantics(
+ button: true,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Container(
+ height: 48,
+ alignment: Alignment.center,
+ child: Text(label, style: AppTheme.f(14, weight: FontWeight.w600, color: context.gc.textSecondary)),
+ ),
+ ),
+ );
+ }
+}
+
+class _WritePicture extends StatelessWidget {
+ const _WritePicture({required this.step, required this.shake});
+
+ final _Step step;
+ final int shake;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final done = step == _Step.done;
+ final failed = step == _Step.failed;
+ final off = step == _Step.off;
+ const phone = 120.0;
+ const box = Size(264, 268);
+ const sticker = 62.0;
+ final phoneLeft = (box.width - phone) / 2;
+ const phoneTop = 4.0;
+ final center = Offset(phoneLeft + phone / 2 - sticker / 2, phoneTop + phone * _phoneRatio / 2 - sticker / 2);
+ final away = Offset(phoneLeft + phone + 14, phoneTop + phone * 1.32);
+ final at = done ? center : away;
+ final badge = done
+ ? _badge(gc.sage, PhosphorIconsBold.check, gc)
+ : failed
+ ? _badge(gc.danger, PhosphorIconsBold.x, gc)
+ : null;
+ return SizedBox(
+ width: box.width,
+ height: box.height,
+ child: Stack(clipBehavior: Clip.none, children: [
+ Positioned(left: phoneLeft, top: phoneTop, child: _PhoneBack(width: phone, dim: off)),
+ AnimatedOpacity(
+ duration: const Duration(milliseconds: 220),
+ opacity: done || off ? 0 : 1,
+ child: Stack(children: [
+ Positioned(
+ left: phoneLeft + phone - 8,
+ top: phoneTop + phone * 1.18,
+ child: Transform.rotate(angle: -math.pi * 0.2, child: _Waves(color: gc.accent, size: 28, flip: true)),
+ ),
+ Positioned(
+ left: phoneLeft + phone + 10,
+ top: phoneTop + phone * 0.98,
+ child: const _NfcTag(),
+ ),
+ ]),
+ ),
+ AnimatedPositioned(
+ duration: const Duration(milliseconds: 520),
+ curve: done ? Curves.easeOutBack : Curves.easeOutCubic,
+ left: at.dx,
+ top: at.dy,
+ child: TweenAnimationBuilder<double>(
+ key: ValueKey(shake),
+ tween: Tween(begin: shake == 0 ? 1 : 0, end: 1),
+ duration: const Duration(milliseconds: 420),
+ builder: (context, v, child) =>
+ Transform.translate(offset: Offset(math.sin(v * math.pi * 5) * (1 - v) * 10, 0), child: child),
+ child: _Sticker(size: sticker, dim: off, badge: badge),
+ ),
+ ),
+ ]),
+ );
+ }
+
+ Widget _badge(Color color, IconData icon, GymColors gc) => Container(
+ width: 24,
+ height: 24,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(color: color, shape: BoxShape.circle),
+ child: Icon(icon, size: 12, color: Colors.white),
+ );
+}
+
+class _Point extends StatelessWidget {
+ const _Point({required this.icon, required this.title, required this.body});
+
+ final IconData icon;
+ final String title;
+ final String body;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 11),
+ child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Padding(
+ padding: const EdgeInsets.only(top: 1),
+ child: Icon(icon, size: 19, color: gc.textSecondary),
+ ),
+ const SizedBox(width: 14),
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(title, style: AppTheme.f(14, weight: FontWeight.w600, color: gc.text)),
+ const SizedBox(height: 3),
+ Text(body, style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textSecondary, height: 1.4)),
+ ]),
+ ),
+ ]),
+ );
+ }
+}
+
+class _TodaySheet extends StatefulWidget {
+ const _TodaySheet();
+
+ @override
+ State<_TodaySheet> createState() => _TodaySheetState();
+}
+
+class _TodaySheetState extends State<_TodaySheet> {
+ static _TodaySheetState? open;
+ String? _picked;
+
+ @override
+ void initState() {
+ super.initState();
+ open = this;
+ }
+
+ @override
+ void dispose() {
+ if (open == this) open = null;
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AnimatedBuilder(animation: fit, builder: (context, _) => _body(context));
+ }
+
+ Widget _body(BuildContext context) {
+ final gc = context.gc;
+ final now = DateTime.now();
+ final resting = fit.restingToday;
+ final routines = resting ? const <Routine>[] : _todayRoutines();
+ final pendingIds = {for (final r in fit.pendingRoutinesOn(now)) r.id};
+ Routine? routine;
+ for (final r in routines) {
+ if (r.id == _picked) routine = r;
+ }
+ routine ??= routines.where((r) => pendingIds.contains(r.id)).firstOrNull ?? routines.lastOrNull;
+ final done = routine != null && !pendingIds.contains(routine.id);
+ final next = resting && !fit.rotating ? fit.nextPlannedAfter(now) : null;
+ final upcoming = resting ? next?.routine ?? fit.rotationUpcoming : null;
+ final exercises = routine == null ? const <Exercise>[] : fit.routineExercises(routine);
+ final title = resting ? t.restDayShort : (routine == null ? '' : fit.routineTitle(routine));
+ final subtitle = resting
+ ? [
+ if (upcoming != null) t.rotationRestUpNext(fit.routineTitle(upcoming)),
+ if (next != null) t.weekdayShort(next.day.weekday),
+ ].join(' · ')
+ : done
+ ? t.routineDoneToday
+ : t.exerciseCount(exercises.length);
+
+ void start() {
+ final nav = Navigator.of(context);
+ final id = routine?.id;
+ nav.pop();
+ if (resting || id == null) {
+ showStartSheet(context);
+ return;
+ }
+ final fresh = fit.routines.where((r) => r.id == id).firstOrNull;
+ if (fresh != null && fresh.exerciseIds.isNotEmpty) fit.startRoutine(fresh);
+ }
+
+ return Container(
+ padding: sheetPad(context),
+ constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(context).height * 0.88),
+ decoration: sheetDecoration(gc),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const SheetHandle(),
+ const SizedBox(height: 16),
+ Row(children: [
+ if (resting) ...[
+ Icon(PhosphorIconsFill.bed, size: 14, color: gc.sage),
+ const SizedBox(width: 7),
+ ],
+ Flexible(child: SectionLabel(resting ? t.weeklyPlan : t.todaysRoutine)),
+ ]),
+ const SizedBox(height: 8),
+ Text(title,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(28, weight: FontWeight.w800, color: gc.text, height: 1.1)),
+ if (subtitle.isNotEmpty) ...[
+ const SizedBox(height: 6),
+ Text(subtitle, style: AppTheme.f(13, weight: FontWeight.w500, color: gc.textSecondary)),
+ ],
+ if (routines.length > 1) ...[
+ const SizedBox(height: 14),
+ Wrap(spacing: 8, runSpacing: 8, children: [
+ for (final r in routines)
+ Pill(
+ label: '${pendingIds.contains(r.id) ? '' : '✓ '}${fit.routineTitle(r)}',
+ bg: r.id == routine?.id ? gc.ember : gc.bgRaised2,
+ fg: r.id == routine?.id ? gc.onEmber : gc.textSecondary,
+ vPad: 7,
+ onTap: () {
+ HapticFeedback.selectionClick();
+ setState(() => _picked = r.id);
+ },
+ ),
+ ]),
+ ],
+ if (resting) ...[
+ const SizedBox(height: 14),
+ Text(t.todayRestBody,
+ style: AppTheme.f(13.5, weight: FontWeight.w500, color: gc.textSecondary, height: 1.45)),
+ ],
+ if (exercises.isNotEmpty) ...[
+ const SizedBox(height: 16),
+ Flexible(
+ child: SingleChildScrollView(
+ child: Container(
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(20)),
+ clipBehavior: Clip.antiAlias,
+ child: Column(children: [
+ for (var i = 0; i < exercises.length; i++) ...[
+ if (i > 0)
+ Container(
+ height: 1,
+ margin: const EdgeInsetsDirectional.only(start: 72),
+ color: gc.border.withValues(alpha: 0.6),
+ ),
+ Padding(
+ padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 16, 8),
+ child: Row(children: [
+ SizedBox(
+ width: 44,
+ child: ExerciseMedia(ex: exercises[i], height: 44, radius: 12, bordered: false),
+ ),
+ const SizedBox(width: 16),
+ Expanded(
+ child: Text(exerciseName(exercises[i]),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(14, weight: FontWeight.w600, color: gc.text)),
+ ),
+ ]),
+ ),
+ ],
+ ]),
+ ),
+ ),
+ ),
+ ],
+ const SizedBox(height: 20),
+ PrimaryButton(
+ label: resting
+ ? t.trainAnyway
+ : done
+ ? t.trainAgain
+ : t.startWorkout,
+ icon: Ic.play,
+ bg: resting || done ? gc.bgRaised2 : null,
+ fg: resting || done ? gc.text : null,
+ onTap: start,
+ ),
+ _TextAction(label: resting ? sentenceCase(t.done) : t.todayNotNow, onTap: () => Navigator.of(context).pop()),
+ ],
+ ),
+ );
+ }
+}