Skip to content

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

Pick several places at onboarding and set body numbers on rulers

InlitXd6200fcedc4d
diff --git a/lib/screens/measures_screen.dart b/lib/screens/measures_screen.dart
index f918b2e..29a122e 100644
--- a/lib/screens/measures_screen.dart
+++ b/lib/screens/measures_screen.dart
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
import '../l10n/l10n.dart';
@@ -8,6 +7,10 @@ import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
import '../widgets/charts.dart';
+import '../widgets/dialogs.dart';
+import '../widgets/glass.dart';
+import '../widgets/rolling_text.dart';
+import '../widgets/ruler_picker.dart';
import '../widgets/svg_icon.dart';
import '../widgets/ui_kit.dart';
@@ -21,6 +24,7 @@ class MeasuresScreen extends StatelessWidget {
return SafeArea(
bottom: false,
child: SingleChildScrollView(
+ clipBehavior: Clip.none,
padding: const EdgeInsets.fromLTRB(20, 12, 20, 40),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -105,8 +109,13 @@ class _MeasureRow extends StatelessWidget {
),
if (series.length > 1)
SizedBox(
- width: 84,
- child: Sparkline(values: series, height: 34, color: gc.accent),
+ width: 108,
+ child: Sparkline(
+ values: [for (final v in series) fit.toDisplayMeasure(measureKey, v)],
+ height: 38,
+ color: gc.accent,
+ scale: fmt,
+ ),
)
else
Icon(PhosphorIconsRegular.plusCircle, size: 20, color: gc.textTertiary),
@@ -118,7 +127,7 @@ class _MeasureRow extends StatelessWidget {
}
}
-Future<void> showMeasureSheet(BuildContext context, String key) => showModalBottomSheet<void>(
+Future<void> showMeasureSheet(BuildContext context, String key) => showAppSheet<void>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
@@ -135,105 +144,134 @@ class _MeasureSheet extends StatefulWidget {
}
class _MeasureSheetState extends State<_MeasureSheet> {
- late final TextEditingController _value = TextEditingController(
- text: () {
- final latest = fit.latestMeasure(widget.measureKey);
- return latest == null ? '' : fit.measureValue(widget.measureKey, latest.value);
- }(),
- );
+ static const _rangesCm = {
+ 'neck': (20.0, 70.0, 38.0),
+ 'shoulders': (70.0, 180.0, 115.0),
+ 'chest': (60.0, 180.0, 100.0),
+ 'arm': (15.0, 70.0, 34.0),
+ 'forearm': (15.0, 50.0, 28.0),
+ 'waist': (40.0, 180.0, 84.0),
+ 'hips': (50.0, 180.0, 98.0),
+ 'thigh': (30.0, 100.0, 56.0),
+ 'calf': (20.0, 70.0, 38.0),
+ };
- @override
- void dispose() {
- _value.dispose();
- super.dispose();
+ String get _key => widget.measureKey;
+ bool get _pct => fit.isPercent(_key);
+ double get _step => _pct ? 0.5 : (fit.isInches ? 0.25 : 0.5);
+ int get _major => _pct ? 10 : (fit.isInches ? 4 : 10);
+
+ (double, double) get _range {
+ if (_pct) return (3, 60);
+ final r = _rangesCm[_key] ?? (10.0, 200.0, 50.0);
+ return (_snap(fit.toDisplayCm(r.$1)), _snap(fit.toDisplayCm(r.$2)));
}
+ double _snap(double v) => (v / _step).round() * _step;
+
+ late double _value = () {
+ final latest = fit.latestMeasure(_key);
+ if (latest != null) return _snap(fit.toDisplayMeasure(_key, latest.value));
+ if (_pct) return 20.0;
+ return _snap(fit.toDisplayCm((_rangesCm[_key] ?? (10.0, 200.0, 50.0)).$3));
+ }();
+
+ String _show(double v) => v.toStringAsFixed(_step < 0.5 ? 2 : 1);
+
void _save() {
- final parsed = double.tryParse(_value.text.trim().replaceAll(',', '.'));
- if (parsed == null || parsed <= 0) return;
- fit.addMeasure(widget.measureKey, parsed);
+ if (_value <= 0) return;
+ fit.addMeasure(_key, _value);
Navigator.of(context).pop();
}
+ Future<void> _type() async {
+ final typed = await askNumber(context, title: t.measureName(_key), initial: _show(_value), decimal: true);
+ if (typed == null || !mounted) return;
+ final (lo, hi) = _range;
+ setState(() => _value = _snap(typed.clamp(lo, hi)));
+ }
+
@override
Widget build(BuildContext context) {
final gc = context.gc;
- final history = fit.measureHistory(widget.measureKey);
+ final history = fit.measureHistory(_key);
+ final (lo, hi) = _range;
- return Padding(
- padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
- child: Container(
- decoration: BoxDecoration(
- color: gc.bg,
- border: Border.all(color: gc.border),
- borderRadius: const BorderRadius.vertical(top: Radius.circular(26)),
- ),
- clipBehavior: Clip.antiAlias,
- child: SafeArea(
- top: false,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- SheetHandle(color: gc.border, margin: const EdgeInsets.symmetric(vertical: 12)),
- Padding(
- padding: const EdgeInsets.fromLTRB(20, 4, 20, 20),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- Text(t.measureName(widget.measureKey).toUpperCase(),
- style: AppTheme.d(18,
- weight: FontWeight.w700, color: gc.text, letterSpacing: 1)),
- const SizedBox(height: 16),
- Row(
- children: [
- Expanded(
- child: TextField(
- controller: _value,
- autofocus: true,
- keyboardType: const TextInputType.numberWithOptions(decimal: true),
- inputFormatters: [
- FilteringTextInputFormatter.allow(RegExp(r'[0-9.,]')),
- ],
- onSubmitted: (_) => _save(),
- cursorColor: gc.accent,
- style: AppTheme.d(22, weight: FontWeight.w700, color: gc.text),
- decoration: InputDecoration(
- hintText: '0',
- hintStyle: AppTheme.d(22, weight: FontWeight.w700, color: gc.textTertiary),
- suffixText: fit.measureUnit(widget.measureKey),
- suffixStyle: AppTheme.d(14, weight: FontWeight.w600, color: gc.textSecondary),
- filled: true,
- fillColor: gc.bgRaised,
- contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(14),
- borderSide: BorderSide(color: gc.border)),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(14),
- borderSide: BorderSide(color: gc.accent)),
- ),
- ),
- ),
- const SizedBox(width: 12),
- SizedBox(
- width: 120,
- child: PrimaryButton(label: t.save, onTap: _save, height: 52),
+ return Container(
+ decoration: BoxDecoration(
+ color: gc.bg,
+ border: Border.all(color: gc.border),
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(26)),
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: SafeArea(
+ top: false,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SheetHandle(color: gc.border, margin: const EdgeInsets.symmetric(vertical: 12)),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 4, 20, 20),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Row(children: [
+ Expanded(
+ child: Text(t.measureName(_key),
+ style: AppTheme.f(17, weight: FontWeight.w800, color: gc.text)),
+ ),
+ Semantics(
+ button: true,
+ label: t.measureName(_key),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _type,
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: Icon(PhosphorIconsRegular.keyboard, size: 20, color: gc.textSecondary),
),
+ ),
+ ),
+ ]),
+ const SizedBox(height: 6),
+ Center(
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.baseline,
+ textBaseline: TextBaseline.alphabetic,
+ children: [
+ RollingText(_show(_value),
+ style: AppTheme.f(54, weight: FontWeight.w800, color: gc.text, height: 1.1)),
+ const SizedBox(width: 6),
+ Text(fit.measureUnit(_key),
+ style: AppTheme.f(18, weight: FontWeight.w700, color: gc.textSecondary)),
],
),
- if (history.isNotEmpty) ...[
- const SizedBox(height: 22),
- Text(t.measureHistory,
- style: AppTheme.d(12,
- weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 2)),
- const SizedBox(height: 10),
- for (final m in history.take(6)) _historyRow(gc, m),
- ],
+ ),
+ const SizedBox(height: 14),
+ RulerPicker(
+ value: _value.clamp(lo, hi),
+ min: lo,
+ max: hi,
+ step: _step,
+ majorEvery: _major,
+ label: (v) => '${v.round()}',
+ onChanged: (v) => setState(() => _value = v),
+ ),
+ const SizedBox(height: 18),
+ PrimaryButton(label: t.save, onTap: _save, height: 54),
+ if (history.isNotEmpty) ...[
+ const SizedBox(height: 22),
+ Text(t.measureHistory,
+ style: AppTheme.d(12,
+ weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 2)),
+ const SizedBox(height: 10),
+ for (final m in history.take(6)) _historyRow(gc, m),
],
- ),
+ ],
),
- ],
- ),
+ ),
+ ],
),
),
);
diff --git a/lib/screens/onboarding_screen.dart b/lib/screens/onboarding_screen.dart
index 09e5535..89a43f5 100644
--- a/lib/screens/onboarding_screen.dart
+++ b/lib/screens/onboarding_screen.dart
@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
+import '../catalog/exercise_catalog.dart';
import '../l10n/l10n.dart';
import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
import '../widgets/app_background.dart';
+import '../widgets/body_rulers.dart';
+import '../widgets/entrance.dart';
import '../widgets/ui_kit.dart';
class OnboardingScreen extends StatefulWidget {
@@ -15,22 +18,17 @@ class OnboardingScreen extends StatefulWidget {
State<OnboardingScreen> createState() => _OnboardingScreenState();
}
-class _OnboardingScreenState extends State<OnboardingScreen>
- with SingleTickerProviderStateMixin {
+class _OnboardingScreenState extends State<OnboardingScreen> {
final _page = PageController();
late final TextEditingController _name = TextEditingController();
- late final AnimationController _reveal = AnimationController(
- vsync: this,
- duration: const Duration(milliseconds: 680),
- )..forward();
int _index = 0;
- static const _last = 4;
+ static const _last = 5;
+ final Map<String, Set<String>> _places = {};
@override
void dispose() {
_page.dispose();
_name.dispose();
- _reveal.dispose();
super.dispose();
}
@@ -38,31 +36,23 @@ class _OnboardingScreenState extends State<OnboardingScreen>
_page.animateToPage(i, duration: const Duration(milliseconds: 340), curve: Curves.easeOutCubic);
}
- void _onPage(int i) {
- setState(() => _index = i);
- _reveal.forward(from: 0);
- }
+ void _onPage(int i) => setState(() => _index = i);
void _finish() {
final typed = _name.text.trim();
if (typed.isNotEmpty) fit.updateProfile(name: typed);
+ String? first;
+ for (final preset in kPlacePresets) {
+ final gear = _places[preset];
+ if (gear == null) continue;
+ final id = fit.addPlace(t.placePresetName(preset), equipment: {...gear, 'Bodyweight'});
+ if (id.isNotEmpty) first ??= id;
+ }
+ if (first != null && fit.activePlaceId != first) fit.setActivePlace(first);
fit.completeOnboarding();
}
- Widget _in(int order, Widget child) {
- return AnimatedBuilder(
- animation: _reveal,
- builder: (context, kid) {
- final v = Curves.easeOutCubic
- .transform(((_reveal.value - 0.08 * order) / 0.6).clamp(0.0, 1.0));
- return Opacity(
- opacity: v,
- child: Transform.translate(offset: Offset(0, 20 * (1 - v)), child: kid),
- );
- },
- child: child,
- );
- }
+ Widget _in(int order, Widget child) => Rise(index: order, child: child);
@override
Widget build(BuildContext context) {
@@ -85,9 +75,10 @@ class _OnboardingScreenState extends State<OnboardingScreen>
children: [
_welcome(gc),
_nameStep(gc),
+ _unitsStep(gc),
_bodyStep(gc),
_goalStep(gc),
- _unitsStep(gc),
+ _placeStep(gc),
],
),
),
@@ -170,43 +161,40 @@ class _OnboardingScreenState extends State<OnboardingScreen>
Widget _step(
GymColors gc, {
required int step,
- required IconData icon,
required String title,
required String why,
required Widget child,
}) {
return LayoutBuilder(
builder: (context, box) => SingleChildScrollView(
- padding: const EdgeInsets.fromLTRB(24, 20, 24, 20),
+ padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: box.maxHeight - 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- _in(0, _badge(gc, icon)),
- const SizedBox(height: 22),
+ _in(0, Padding(padding: const EdgeInsets.only(left: 4), child: _label(gc, t.onbStep(step, _last)))),
+ const SizedBox(height: 10),
_in(
1,
- Text(t.onbStep(step, _last).toUpperCase(),
- style: AppTheme.f(10.5,
- weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.6)),
- ),
- const SizedBox(height: 9),
- _in(
- 2,
- Text(title,
- style: AppTheme.f(30, weight: FontWeight.w800, color: gc.text, height: 1.12)),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
+ child: Text(title,
+ style: AppTheme.f(30, weight: FontWeight.w800, color: gc.text, height: 1.12)),
+ ),
),
const SizedBox(height: 10),
_in(
- 3,
- Text(why,
- style: AppTheme.f(13.5,
- weight: FontWeight.w500, color: gc.textSecondary, height: 1.45)),
+ 2,
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
+ child: Text(why,
+ style: AppTheme.f(13.5, weight: FontWeight.w500, color: gc.textSecondary, height: 1.45)),
+ ),
),
const SizedBox(height: 26),
- _in(4, child),
+ _in(3, child),
],
),
),
@@ -214,72 +202,82 @@ class _OnboardingScreenState extends State<OnboardingScreen>
);
}
- Widget _badge(GymColors gc, IconData icon) => Align(
- alignment: Alignment.centerLeft,
- child: Container(
- width: 54,
- height: 54,
- decoration: BoxDecoration(
- color: gc.bgRaised,
- borderRadius: BorderRadius.circular(18),
- ),
- child: Icon(icon, size: 24, color: gc.textSecondary),
- ),
+ Widget _label(GymColors gc, String text) => Text(text.toUpperCase(),
+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.3));
+
+ Widget _group(GymColors gc, List<Widget> rows) {
+ return Container(
+ clipBehavior: Clip.antiAlias,
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(20)),
+ child: Column(
+ children: [
+ for (var i = 0; i < rows.length; i++) ...[
+ if (i > 0)
+ Divider(height: 1, thickness: 1, indent: 16, endIndent: 16, color: gc.border.withValues(alpha: 0.6)),
+ rows[i],
+ ],
+ ],
+ ),
+ );
+ }
+
+ Widget _rowIcon(GymColors gc, IconData icon, {Color? color}) => Padding(
+ padding: const EdgeInsets.only(right: 14),
+ child: SizedBox(width: 22, child: Icon(icon, size: 19, color: color ?? gc.textSecondary)),
);
Widget _welcome(GymColors gc) {
return LayoutBuilder(
builder: (context, box) => SingleChildScrollView(
- padding: const EdgeInsets.fromLTRB(24, 20, 24, 20),
+ padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: box.maxHeight - 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.start,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_in(
0,
Center(
child: Image.asset('assets/img/runner.png',
- height: 218, opacity: const AlwaysStoppedAnimation(0.9)),
+ height: 196, opacity: const AlwaysStoppedAnimation(0.9)),
),
),
- const SizedBox(height: 30),
+ const SizedBox(height: 26),
_in(
1,
- Text(t.welcomeKicker.toUpperCase(),
- style: AppTheme.f(10.5,
- weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.6)),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
+ child: Text(t.welcomeKicker.toUpperCase(),
+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.6)),
+ ),
),
const SizedBox(height: 8),
_in(
2,
- Text('GymMane',
- style: AppTheme.f(44, weight: FontWeight.w800, color: gc.text, height: 1)),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
+ child: Text('GymMane',
+ style: AppTheme.f(44, weight: FontWeight.w800, color: gc.text, height: 1)),
+ ),
),
const SizedBox(height: 12),
_in(
3,
- Text(t.welcomeBlurb,
- style: AppTheme.f(14.5,
- weight: FontWeight.w500, color: gc.textSecondary, height: 1.5)),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
+ child: Text(t.welcomeBlurb,
+ style: AppTheme.f(14.5, weight: FontWeight.w500, color: gc.textSecondary, height: 1.5)),
+ ),
),
- const SizedBox(height: 26),
+ const SizedBox(height: 22),
_in(
4,
- SoftCard(
- radius: 22,
- padding: const EdgeInsets.fromLTRB(18, 16, 18, 16),
- child: Column(
- children: [
- _promise(gc, PhosphorIconsRegular.wifiSlash, t.fullyOffline),
- const SizedBox(height: 14),
- _promise(gc, PhosphorIconsRegular.sealCheck, t.freeForever),
- const SizedBox(height: 14),
- _promise(gc, PhosphorIconsRegular.lockKey, t.yoursToTake),
- ],
- ),
- ),
+ _group(gc, [
+ _promise(gc, PhosphorIconsRegular.gift, t.freeForever, t.freeForeverWhy),
+ _promise(gc, PhosphorIconsRegular.wifiSlash, t.fullyOffline, t.fullyOfflineWhy),
+ _promise(gc, PhosphorIconsRegular.export, t.yoursToTake, t.yoursToTakeWhy),
+ ]),
),
],
),
@@ -288,41 +286,59 @@ class _OnboardingScreenState extends State<OnboardingScreen>
);
}
- Widget _promise(GymColors gc, IconData icon, String label) => Row(
- children: [
- Icon(icon, size: 17, color: gc.textSecondary),
- const SizedBox(width: 12),
- Expanded(
- child: Text(label,
- style: AppTheme.f(13, weight: FontWeight.w600, color: gc.text)),
- ),
- ],
+ Widget _promise(GymColors gc, IconData icon, String title, String why) => Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(padding: const EdgeInsets.only(top: 1), child: _rowIcon(gc, icon)),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(title, style: AppTheme.f(14.5, weight: FontWeight.w600, color: gc.text)),
+ const SizedBox(height: 3),
+ Text(why,
+ style: AppTheme.f(12.5, weight: FontWeight.w500, color: gc.textSecondary, height: 1.4)),
+ ],
+ ),
+ ),
+ ],
+ ),
);
Widget _nameStep(GymColors gc) {
return _step(
gc,
step: 1,
- icon: PhosphorIconsRegular.user,
title: t.onbNameTitle,
why: t.onbNameWhy,
- child: TextField(
- controller: _name,
- textCapitalization: TextCapitalization.words,
- textInputAction: TextInputAction.done,
- style: AppTheme.f(20, weight: FontWeight.w700, color: gc.text),
- cursorColor: gc.accent,
- onSubmitted: (_) => _go(2),
- decoration: InputDecoration(
- hintText: t.onbNameHint,
- hintStyle: AppTheme.f(20, weight: FontWeight.w700, color: gc.textTertiary),
- filled: true,
- fillColor: gc.bgRaised,
- contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
- border:
- OutlineInputBorder(borderRadius: BorderRadius.circular(20), borderSide: BorderSide.none),
+ child: _group(gc, [
+ Padding(
+ padding: const EdgeInsets.only(left: 16, right: 8),
+ child: Row(
+ children: [
+ _rowIcon(gc, PhosphorIconsRegular.userCircle),
+ Expanded(
+ child: TextField(
+ controller: _name,
+ textCapitalization: TextCapitalization.words,
+ textInputAction: TextInputAction.done,
+ style: AppTheme.f(17, weight: FontWeight.w700, color: gc.text),
+ cursorColor: gc.accent,
+ onSubmitted: (_) => _go(2),
+ decoration: InputDecoration(
+ hintText: t.onbNameHint,
+ hintStyle: AppTheme.f(17, weight: FontWeight.w600, color: gc.textTertiary),
+ border: InputBorder.none,
+ contentPadding: const EdgeInsets.symmetric(vertical: 20),
+ ),
+ ),
+ ),
+ ],
+ ),
),
- ),
+ ]),
);
}
@@ -330,70 +346,115 @@ class _OnboardingScreenState extends State<OnboardingScreen>
final p = fit.profile;
return _step(
gc,
- step: 2,
- icon: PhosphorIconsRegular.ruler,
+ step: 3,
title: t.onbBodyTitle,
why: t.onbBodyWhy,
- child: SoftCard(
- radius: 22,
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
- child: Column(
- children: [
- _row(gc, t.sexLabel, SegToggle([
- SegOption(t.male, p.sex == 'male', () => _up(() => fit.updateProfile(sex: 'male'))),
- SegOption(
- t.female, p.sex == 'female', () => _up(() => fit.updateProfile(sex: 'female'))),
- ])),
- _divider(gc),
- _stepperRow(gc, t.ageLabel, '${p.age}', () => fit.updateProfile(ageDelta: -1),
- () => fit.updateProfile(ageDelta: 1)),
- _divider(gc),
- _stepperRow(gc, t.heightLabel, '${fmt(p.heightCm)} cm',
- () => fit.updateProfile(heightDelta: -1), () => fit.updateProfile(heightDelta: 1)),
- _divider(gc),
- _stepperRow(
- gc,
- t.weightLabel,
- fit.weightLabel(p.weightKg),
- () => fit.updateProfile(weightDelta: -fit.fromDisplayWeight(fit.isLb ? 1 : 0.5)),
- () => fit.updateProfile(weightDelta: fit.fromDisplayWeight(fit.isLb ? 1 : 0.5))),
- ],
+ child: _group(gc, [
+ _bodyRow(
+ gc,
+ PhosphorIconsRegular.genderIntersex,
+ t.sexLabel,
+ SegToggle([
+ SegOption(t.male, p.sex == 'male', () => _up(() => fit.updateProfile(sex: 'male'))),
+ SegOption(t.female, p.sex == 'female', () => _up(() => fit.updateProfile(sex: 'female'))),
+ ]),
+ ),
+ _valueRow(gc, PhosphorIconsRegular.cake, t.ageLabel, '${p.age}', editAge),
+ _valueRow(gc, PhosphorIconsRegular.ruler, t.heightLabel, fit.heightLabel(p.heightCm), editHeight),
+ _valueRow(gc, PhosphorIconsRegular.scales, t.weightLabel, fit.weightLabel(p.weightKg), editBodyWeight),
+ ]),
+ );
+ }
+
+ Widget _bodyRow(GymColors gc, IconData icon, String label, Widget control) => ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: 58),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ child: Row(
+ children: [
+ _rowIcon(gc, icon),
+ Expanded(
+ child: Text(sentenceCase(label),
+ style: AppTheme.f(14.5, weight: FontWeight.w500, color: gc.text)),
+ ),
+ const SizedBox(width: 12),
+ control,
+ ],
+ ),
+ ),
+ );
+
+ Widget _valueRow(GymColors gc, IconData icon, String label, String value,
+ Future<void> Function(BuildContext) edit) {
+ return Semantics(
+ button: true,
+ label: sentenceCase(label),
+ value: value,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => edit(context).then((_) => _up(() {})),
+ child: _bodyRow(
+ gc,
+ icon,
+ label,
+ Row(mainAxisSize: MainAxisSize.min, children: [
+ Text(value, style: AppTheme.f(15.5, weight: FontWeight.w700, color: gc.text)),
+ const SizedBox(width: 8),
+ Icon(PhosphorIconsBold.caretRight, size: 13, color: gc.textTertiary),
+ ]),
),
),
);
}
Widget _goalStep(GymColors gc) {
+ final goal = fit.profile.weeklyGoal;
return _step(
gc,
- step: 3,
- icon: PhosphorIconsRegular.target,
+ step: 4,
title: t.onbGoalTitle,
why: t.onbGoalWhy,
- child: Column(
- children: [
- Text(t.perWeek(fit.profile.weeklyGoal),
- style: AppTheme.f(26, weight: FontWeight.w800, color: gc.text)),
- const SizedBox(height: 20),
- Wrap(
- spacing: 9,
- runSpacing: 9,
- alignment: WrapAlignment.center,
- children: [
- for (int n = 2; n <= 7; n++)
- Pill(
- label: '$n×',
- bg: fit.profile.weeklyGoal == n ? gc.ember : gc.bgRaised,
- fg: fit.profile.weeklyGoal == n ? gc.onEmber : gc.textSecondary,
- onTap: () =>
- _up(() => fit.updateProfile(weeklyGoalDelta: n - fit.profile.weeklyGoal)),
- hPad: 20,
- vPad: 13,
- fontSize: 15,
- ),
- ],
- ),
- ],
+ child: Container(
+ padding: const EdgeInsets.fromLTRB(18, 20, 18, 20),
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(20)),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _label(gc, t.weeklyGoal),
+ const SizedBox(height: 8),
+ Text(t.perWeek(goal), style: AppTheme.f(22, weight: FontWeight.w800, color: gc.text)),
+ const SizedBox(height: 20),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ for (var n = 1; n <= 7; n++)
+ Semantics(
+ button: true,
+ selected: n == goal,
+ label: t.perWeek(n),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _up(() => fit.updateProfile(weeklyGoalDelta: n - goal)),
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 220),
+ curve: Curves.easeOutCubic,
+ width: 36,
+ height: 36,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ color: n <= goal ? gc.ember : gc.bgRaised2,
+ shape: BoxShape.circle,
+ ),
+ child: Text('$n',
+ style: AppTheme.f(13.5,
+ weight: FontWeight.w800, color: n <= goal ? gc.onEmber : gc.textTertiary)),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
),
);
}
@@ -401,37 +462,172 @@ class _OnboardingScreenState extends State<OnboardingScreen>
Widget _unitsStep(GymColors gc) {
return _step(
gc,
- step: 4,
- icon: PhosphorIconsRegular.scales,
+ step: 2,
title: t.onbUnitsTitle,
why: t.autofills,
child: Row(
children: [
- for (final u in const ['kg', 'lb'])
- Expanded(
- child: Padding(
- padding: EdgeInsets.only(right: u == 'kg' ? 12 : 0),
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () => _up(() => fit.setUnits(u)),
- child: AnimatedContainer(
+ for (final u in const ['kg', 'lb']) ...[
+ if (u == 'lb') const SizedBox(width: 12),
+ Expanded(child: _unitTile(gc, u)),
+ ],
+ ],
+ ),
+ );
+ }
+
+ Widget _unitTile(GymColors gc, String u) {
+ final on = fit.units == u;
+ final sample = u == 'kg' ? '60 kg · 175 cm · 5 km' : '135 lb · 5′9″ · 3 mi';
+ return Semantics(
+ button: true,
+ selected: on,
+ label: u,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _up(() => fit.setUnits(u)),
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 220),
+ curve: Curves.easeOutCubic,
+ height: 118,
+ padding: const EdgeInsets.fromLTRB(18, 16, 14, 16),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(color: on ? gc.ember : Colors.transparent, width: 1.6),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ const Spacer(),
+ AnimatedOpacity(
duration: const Duration(milliseconds: 200),
- curve: Curves.easeOutCubic,
- height: 96,
- decoration: BoxDecoration(
- color: fit.units == u ? gc.ember : gc.bgRaised,
- borderRadius: BorderRadius.circular(22),
+ opacity: on ? 1 : 0,
+ child: Icon(PhosphorIconsFill.checkCircle, size: 18, color: gc.ember),
+ ),
+ ],
+ ),
+ const Spacer(),
+ Text(u, style: AppTheme.f(30, weight: FontWeight.w800, color: on ? gc.ember : gc.text, height: 1)),
+ const SizedBox(height: 6),
+ Text(sample, style: AppTheme.f(11.5, weight: FontWeight.w600, color: gc.textTertiary)),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ static const _placeIcons = {
+ 'gym': PhosphorIconsRegular.barbell,
+ 'home': PhosphorIconsRegular.house,
+ 'outdoors': PhosphorIconsRegular.tree,
+ };
+
+ Widget _placeStep(GymColors gc) {
+ return _step(
+ gc,
+ step: 5,
+ title: t.onbPlaceTitle,
+ why: t.onbPlaceWhy,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ _group(gc, [for (final preset in kPlacePresets) _placeRow(gc, preset)]),
+ AnimatedSize(
+ duration: const Duration(milliseconds: 260),
+ curve: Curves.easeOutCubic,
+ alignment: Alignment.topCenter,
+ child: _places.isEmpty
+ ? const SizedBox(width: double.infinity)
+ : Padding(
+ padding: const EdgeInsets.only(top: 20),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ for (final preset in kPlacePresets)
+ if (_places[preset] case final gear?) ...[
+ Padding(
+ padding: const EdgeInsets.only(left: 4),
+ child: _label(
+ gc,
+ _places.length > 1
+ ? '${t.placePresetName(preset)} · ${t.onbPlaceGear}'
+ : t.onbPlaceGear),
+ ),
+ const SizedBox(height: 10),
+ Wrap(
+ spacing: 8,
+ runSpacing: 8,
+ children: [
+ for (final e in kFilterEquipment)
+ if (e != 'Bodyweight')
+ Pill(
+ label: t.equipment(e),
+ bg: gear.contains(e) ? gc.ember : gc.bgRaised,
+ fg: gear.contains(e) ? gc.onEmber : gc.textSecondary,
+ onTap: () => setState(() {
+ if (!gear.remove(e)) gear.add(e);
+ }),
+ hPad: 14,
+ vPad: 8,
+ fontSize: 12.5,
+ ),
+ ],
+ ),
+ const SizedBox(height: 18),
+ ],
+ ],
),
- alignment: Alignment.center,
- child: Text(u,
- style: AppTheme.f(28,
- weight: FontWeight.w800,
- color: fit.units == u ? gc.onEmber : gc.text)),
),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _placeRow(GymColors gc, String preset) {
+ final on = _places.containsKey(preset);
+ final gear = {...?(_places[preset] ?? kPlacePresetGear[preset]), 'Bodyweight'};
+ final n = fit.allExercises.where((e) => gear.contains(e.equipment)).length;
+ return Semantics(
+ button: true,
+ selected: on,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => setState(() {
+ if (_places.remove(preset) == null) {
+ _places[preset] = {...?kPlacePresetGear[preset]}..remove('Bodyweight');
+ }
+ }),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
+ child: Row(
+ children: [
+ _rowIcon(gc, _placeIcons[preset]!, color: on ? gc.ember : null),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(t.placePresetName(preset),
+ style: AppTheme.f(14.5,
+ weight: on ? FontWeight.w800 : FontWeight.w600, color: on ? gc.ember : gc.text)),
+ const SizedBox(height: 2),
+ Text(t.exerciseCount(n),
+ style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textSecondary)),
+ ],
),
),
- ),
- ],
+ AnimatedOpacity(
+ duration: const Duration(milliseconds: 200),
+ opacity: on ? 1 : 0,
+ child: Icon(PhosphorIconsFill.checkCircle, size: 18, color: gc.ember),
+ ),
+ ],
+ ),
+ ),
),
);
}
@@ -440,35 +636,6 @@ class _OnboardingScreenState extends State<OnboardingScreen>
action();
setState(() {});
}
-
- Widget _divider(GymColors gc) => Container(height: 1, color: gc.bgRaised2);
-
- Widget _row(GymColors gc, String label, Widget control) => Padding(
- padding: const EdgeInsets.symmetric(vertical: 12),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(label, style: AppTheme.f(13, weight: FontWeight.w600, color: gc.textSecondary)),
- control,
- ],
- ),
- );
-
- Widget _stepperRow(
- GymColors gc, String label, String value, VoidCallback dec, VoidCallback inc) =>
- _row(
- gc,
- label,
- StepperControl(
- value: value,
- minWidth: 78,
- btnSize: 34,
- gap: 12,
- fontSize: 15,
- onDec: () => _up(dec),
- onInc: () => _up(inc),
- ),
- );
}
class _Glow extends StatelessWidget {
diff --git a/lib/screens/places_screen.dart b/lib/screens/places_screen.dart
index 7fe96aa..0ebb8d0 100644
--- a/lib/screens/places_screen.dart
+++ b/lib/screens/places_screen.dart
@@ -8,6 +8,7 @@ import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
import '../widgets/dialogs.dart';
+import '../widgets/glass.dart';
import '../widgets/ui_kit.dart';
class PlacesScreen extends StatelessWidget {
@@ -296,7 +297,7 @@ class PlacesScreen extends StatelessWidget {
void _editPlates(BuildContext context, GymPlace place) {
final gc = context.gc;
- showModalBottomSheet<void>(
+ showAppSheet<void>(
context: context,
backgroundColor: Colors.transparent,
isScrollControlled: true,
@@ -393,7 +394,7 @@ class PlacesScreen extends StatelessWidget {
Future<void> _rename(BuildContext context, GymPlace? place) async {
final gc = context.gc;
final controller = TextEditingController(text: place?.name ?? '');
- final name = await showDialog<String>(
+ final name = await showAppDialog<String>(
context: context,
builder: (dctx) => appDialog(
gc,
diff --git a/lib/state/measures_state.dart b/lib/state/measures_state.dart
index 74c0653..6338e1c 100644
--- a/lib/state/measures_state.dart
+++ b/lib/state/measures_state.dart
@@ -21,6 +21,14 @@ mixin MeasuresState on FitCore {
String cmLabel(double cm) => '${fmt(_round1(toDisplayCm(cm)))} $lengthUnit';
+ String heightLabel(double cm) {
+ if (!isInches) return '${fmt(cm.round())} cm';
+ final inches = (cm / _cmPerInch).round();
+ return '${inches ~/ 12}′ ${inches % 12}″';
+ }
+
+ double get heightStep => isInches ? _cmPerInch : 1;
+
double get cmStep => isInches ? _cmPerInch / 2 : 1;
double get girthStep => isInches ? _cmPerInch / 4 : 0.5;
diff --git a/lib/state/places_state.dart b/lib/state/places_state.dart
index 165df16..0e398b5 100644
--- a/lib/state/places_state.dart
+++ b/lib/state/places_state.dart
@@ -24,7 +24,8 @@ mixin PlacesState on FitCore, LibraryState {
return place == null ? kEquipment.toSet() : {...place.equipment, 'Bodyweight'};
}
- bool fitsHere(Exercise ex) => activePlace == null || gearHere.contains(ex.equipment);
+ bool fitsHere(Exercise ex) =>
+ activePlace == null || gearHere.contains(ex.equipment) || isCustom(ex.id);
int placeExerciseCount(GymPlace place) {
final gear = {...place.equipment, 'Bodyweight'};
diff --git a/lib/widgets/body_rulers.dart b/lib/widgets/body_rulers.dart
new file mode 100644
index 0000000..2d1ff71
--- /dev/null
+++ b/lib/widgets/body_rulers.dart
@@ -0,0 +1,54 @@
+import 'package:flutter/widgets.dart';
+
+import '../l10n/l10n.dart';
+import '../state/fit_state.dart';
+import 'ruler_picker.dart';
+
+Future<void> editAge(BuildContext context) async {
+ final age = fit.profile.age;
+ final v = await askRuler(context,
+ title: t.ageLabel, value: age.toDouble(), min: 10, max: 90, step: 1, majorEvery: 5);
+ if (v != null) fit.updateProfile(ageDelta: v.round() - age);
+}
+
+Future<void> editHeight(BuildContext context) async {
+ final cm = fit.profile.heightCm;
+ if (fit.isInches) {
+ String feet(double v) => '${v.round() ~/ 12}′${v.round() % 12}″';
+ final v = await askRuler(context,
+ title: t.heightLabel,
+ value: (cm / 2.54).roundToDouble(),
+ min: 40,
+ max: 96,
+ step: 1,
+ majorEvery: 12,
+ format: feet,
+ tickLabel: feet,
+ vertical: true);
+ if (v != null) fit.updateProfile(heightDelta: v * 2.54 - cm);
+ return;
+ }
+ final v = await askRuler(context,
+ title: t.heightLabel,
+ value: cm.roundToDouble(),
+ min: 100,
+ max: 250,
+ step: 1,
+ majorEvery: 10,
+ unit: 'cm',
+ vertical: true);
+ if (v != null) fit.updateProfile(heightDelta: v - cm);
+}
+
+Future<void> editBodyWeight(BuildContext context) async {
+ final kg = fit.profile.weightKg;
+ final v = await askRuler(context,
+ title: t.weightLabel,
+ value: (fit.toDisplayWeight(kg) * 2).round() / 2,
+ min: fit.isLb ? 66 : 30,
+ max: fit.isLb ? 550 : 250,
+ step: fit.isLb ? 1 : 0.5,
+ majorEvery: 10,
+ unit: fit.units);
+ if (v != null) fit.updateProfile(weightDelta: fit.fromDisplayWeight(v) - kg);
+}
diff --git a/lib/widgets/ruler_picker.dart b/lib/widgets/ruler_picker.dart
new file mode 100644
index 0000000..a49a7a4
--- /dev/null
+++ b/lib/widgets/ruler_picker.dart
@@ -0,0 +1,363 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import 'dialogs.dart';
+import 'glass.dart';
+import 'rolling_text.dart';
+import 'ui_kit.dart';
+
+class RulerPicker extends StatefulWidget {
+ const RulerPicker({
+ super.key,
+ required this.value,
+ required this.min,
+ required this.max,
+ required this.step,
+ required this.onChanged,
+ this.majorEvery = 10,
+ this.label,
+ this.height = 86,
+ this.axis = Axis.horizontal,
+ });
+
+ final double value;
+ final double min;
+ final double max;
+ final double step;
+ final ValueChanged<double> onChanged;
+ final int majorEvery;
+ final String Function(double value)? label;
+ final double height;
+ final Axis axis;
+
+ @override
+ State<RulerPicker> createState() => _RulerPickerState();
+}
+
+class _RulerPickerState extends State<RulerPicker> {
+ static const _gap = 11.0;
+ late final ScrollController _scroll = ScrollController(initialScrollOffset: _offsetOf(widget.value));
+ late int _index = _indexOf(widget.value);
+
+ int get _count => ((widget.max - widget.min) / widget.step).round() + 1;
+
+ int _indexOf(double v) => ((v.clamp(widget.min, widget.max) - widget.min) / widget.step).round();
+
+ double _offsetOf(double v) => _indexOf(v) * _gap;
+
+ double _valueAt(int i) {
+ final raw = widget.min + i * widget.step;
+ return (raw * 1000).round() / 1000;
+ }
+
+ @override
+ void didUpdateWidget(RulerPicker old) {
+ super.didUpdateWidget(old);
+ final wanted = _indexOf(widget.value);
+ if (wanted != _index && _scroll.hasClients && !_scroll.position.isScrollingNotifier.value) {
+ _index = wanted;
+ _scroll.animateTo(wanted * _gap, duration: const Duration(milliseconds: 260), curve: Curves.easeOutCubic);
+ }
+ }
+
+ @override
+ void dispose() {
+ _scroll.dispose();
+ super.dispose();
+ }
+
+ bool _onScroll(ScrollNotification n) {
+ if (n is ScrollUpdateNotification || n is ScrollEndNotification) {
+ final i = (_scroll.offset / _gap).round().clamp(0, _count - 1);
+ if (i != _index) {
+ _index = i;
+ HapticFeedback.selectionClick();
+ widget.onChanged(_valueAt(i));
+ }
+ }
+ return false;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final vertical = widget.axis == Axis.vertical;
+ return LayoutBuilder(builder: (context, box) {
+ final side = (vertical ? widget.height : box.maxWidth) / 2 - _gap / 2;
+ return SizedBox(
+ height: widget.height,
+ child: Stack(
+ alignment: vertical ? Alignment.centerRight : Alignment.topCenter,
+ children: [
+ ShaderMask(
+ blendMode: BlendMode.dstIn,
+ shaderCallback: (r) => LinearGradient(
+ begin: vertical ? Alignment.topCenter : Alignment.centerLeft,
+ end: vertical ? Alignment.bottomCenter : Alignment.centerRight,
+ colors: const [Color(0x00000000), Color(0xFF000000), Color(0xFF000000), Color(0x00000000)],
+ stops: const [0, 0.18, 0.82, 1],
+ ).createShader(r),
+ child: NotificationListener<ScrollNotification>(
+ onNotification: _onScroll,
+ child: ListView.builder(
+ controller: _scroll,
+ scrollDirection: widget.axis,
+ reverse: vertical,
+ physics: const _SnapPhysics(_gap),
+ padding: vertical ? EdgeInsets.symmetric(vertical: side) : EdgeInsets.symmetric(horizontal: side),
+ itemExtent: _gap,
+ itemCount: _count,
+ itemBuilder: (context, i) {
+ final major = i % widget.majorEvery == 0;
+ final half = !major && widget.majorEvery % 2 == 0 && i % (widget.majorEvery ~/ 2) == 0;
+ return _Tick(
+ major: major,
+ half: half,
+ vertical: vertical,
+ label: major ? (widget.label ?? _plain)(_valueAt(i)) : null,
+ color: gc.textTertiary,
+ labelColor: gc.textSecondary,
+ );
+ },
+ ),
+ ),
+ ),
+ IgnorePointer(
+ child: Container(
+ width: vertical ? 44 : 3,
+ height: vertical ? 3 : 44,
+ decoration: BoxDecoration(color: gc.accent, borderRadius: BorderRadius.circular(2)),
+ ),
+ ),
+ ],
+ ),
+ );
+ });
+ }
+
+ static String _plain(double v) => v == v.roundToDouble() ? '${v.round()}' : '$v';
+}
+
+class _Tick extends StatelessWidget {
+ const _Tick({
+ required this.major,
+ required this.half,
+ required this.label,
+ required this.color,
+ required this.labelColor,
+ this.vertical = false,
+ });
+
+ final bool major;
+ final bool half;
+ final String? label;
+ final Color color;
+ final Color labelColor;
+ final bool vertical;
+
+ @override
+ Widget build(BuildContext context) {
+ if (vertical) {
+ return OverflowBox(
+ maxHeight: 40,
+ alignment: Alignment.centerRight,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ if (label != null) ...[
+ Text(label!, maxLines: 1, style: AppTheme.f(12, weight: FontWeight.w700, color: labelColor)),
+ const SizedBox(width: 10),
+ ],
+ Container(
+ width: major ? 34 : (half ? 24 : 16),
+ height: major ? 2 : 1.4,
+ decoration: BoxDecoration(
+ color: major ? labelColor : color.withValues(alpha: half ? 0.9 : 0.6),
+ borderRadius: BorderRadius.circular(1),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+ return OverflowBox(
+ maxWidth: 60,
+ alignment: Alignment.topCenter,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Container(
+ width: major ? 2 : 1.4,
+ height: major ? 34 : (half ? 24 : 16),
+ decoration: BoxDecoration(
+ color: major ? labelColor : color.withValues(alpha: half ? 0.9 : 0.6),
+ borderRadius: BorderRadius.circular(1),
+ ),
+ ),
+ if (label != null) ...[
+ const SizedBox(height: 10),
+ Text(label!, maxLines: 1, style: AppTheme.f(12, weight: FontWeight.w700, color: labelColor)),
+ ],
+ ],
+ ),
+ );
+ }
+}
+
+class _SnapPhysics extends ScrollPhysics {
+ const _SnapPhysics(this.extent, {super.parent});
+
+ final double extent;
+
+ @override
+ _SnapPhysics applyTo(ScrollPhysics? ancestor) => _SnapPhysics(extent, parent: buildParent(ancestor));
+
+ @override
+ Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) {
+ final tolerance = toleranceFor(position);
+ final base = super.createBallisticSimulation(position, velocity);
+ var target = position.pixels;
+ if (base != null) target = base.x(double.infinity);
+ target = ((target / extent).round() * extent).clamp(position.minScrollExtent, position.maxScrollExtent);
+ if ((target - position.pixels).abs() < tolerance.distance && velocity.abs() < tolerance.velocity) {
+ return null;
+ }
+ return ScrollSpringSimulation(
+ SpringDescription.withDampingRatio(mass: 0.6, stiffness: 180, ratio: 1),
+ position.pixels,
+ target,
+ velocity,
+ tolerance: tolerance,
+ );
+ }
+
+ @override
+ bool get allowImplicitScrolling => false;
+}
+
+const rulerCleared = double.nan;
+
+Future<double?> askRuler(
+ BuildContext context, {
+ required String title,
+ required double value,
+ required double min,
+ required double max,
+ required double step,
+ String unit = '',
+ int majorEvery = 10,
+ String Function(double value)? format,
+ String Function(double value)? tickLabel,
+ bool vertical = false,
+ String? hint,
+ String? clearLabel,
+}) {
+ var current = value.clamp(min, max).toDouble();
+ final decimals = step == step.roundToDouble() ? 0 : (step < 0.1 || step * 10 != (step * 10).roundToDouble() ? 2 : 1);
+ String show(double v) => format != null ? format(v) : v.toStringAsFixed(decimals);
+ return showAppSheet<double>(
+ context: context,
+ isScrollControlled: true,
+ builder: (sheet) => StatefulBuilder(
+ builder: (sheet, setSheet) {
+ final gc = sheet.gc;
+ final reading = Row(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.baseline,
+ textBaseline: TextBaseline.alphabetic,
+ children: [
+ RollingText(show(current), style: AppTheme.f(54, weight: FontWeight.w800, color: gc.text, height: 1.1)),
+ if (unit.isNotEmpty) ...[
+ const SizedBox(width: 6),
+ Text(unit, style: AppTheme.f(18, weight: FontWeight.w700, color: gc.textSecondary)),
+ ],
+ ],
+ );
+ final ruler = RulerPicker(
+ value: current,
+ min: min,
+ max: max,
+ step: step,
+ majorEvery: majorEvery,
+ label: tickLabel,
+ axis: vertical ? Axis.vertical : Axis.horizontal,
+ height: vertical ? 300 : 86,
+ onChanged: (v) => setSheet(() => current = v),
+ );
+ return Container(
+ padding: sheetPad(sheet),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const SheetHandle(),
+ const SizedBox(height: 14),
+ Row(children: [
+ Expanded(
+ child: Text(titleCase(title),
+ style: AppTheme.f(15, weight: FontWeight.w700, color: gc.textSecondary)),
+ ),
+ Semantics(
+ button: true,
+ label: title,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () async {
+ final typed = await askNumber(sheet,
+ title: title, initial: show(current), decimal: step != step.roundToDouble());
+ if (typed == null) return;
+ setSheet(() => current = ((typed.clamp(min, max) / step).round() * step).toDouble());
+ },
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: Icon(PhosphorIconsRegular.keyboard, size: 20, color: gc.textSecondary),
+ ),
+ ),
+ ),
+ ]),
+ const SizedBox(height: 10),
+ if (vertical)
+ Row(children: [
+ Expanded(child: Center(child: reading)),
+ SizedBox(width: 130, child: ruler),
+ ])
+ else ...[
+ Center(child: reading),
+ const SizedBox(height: 18),
+ ruler,
+ ],
+ if (hint != null) ...[
+ const SizedBox(height: 14),
+ Text(hint,
+ textAlign: TextAlign.center,
+ style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textTertiary, height: 1.4)),
+ ],
+ const SizedBox(height: 18),
+ PrimaryButton(label: t.set, onTap: () => Navigator.of(sheet).pop(current)),
+ if (clearLabel != null)
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => Navigator.of(sheet).pop(rulerCleared),
+ child: SizedBox(
+ height: 48,
+ child: Center(
+ child: Text(clearLabel,
+ style: AppTheme.f(14, weight: FontWeight.w600, color: gc.textSecondary)),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ ),
+ );
+}