Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Add performance modes and a smoothness step to onboarding (#307)
InlitX79860805a8bb
diff --git a/lib/screens/onboarding_screen.dart b/lib/screens/onboarding_screen.dartindex c83d41d..760cb49 100644--- a/lib/screens/onboarding_screen.dart+++ b/lib/screens/onboarding_screen.dart@@ -1,6 +1,7 @@import 'dart:math' as math;import 'package:flutter/material.dart';+import 'package:flutter/scheduler.dart';import 'package:flutter/services.dart';import 'package:image_picker/image_picker.dart';import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';@@ -8,6 +9,7 @@ import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';import '../catalog/body_art.dart';import '../catalog/exercise_catalog.dart';import '../l10n/l10n.dart';+import '../services/device_kind.dart';import '../state/fit_state.dart';import '../theme/app_colors.dart';import '../theme/app_theme.dart';@@ -17,6 +19,7 @@ import '../widgets/body_map.dart';import '../widgets/entrance.dart';import '../widgets/photo_source_sheet.dart';import '../widgets/rolling_text.dart';+import '../widgets/speed_panel.dart';import '../widgets/ui_kit.dart';class OnboardingScreen extends StatefulWidget {@@ -32,11 +35,48 @@ class _OnboardingScreenState extends State<OnboardingScreen> {final _at = ValueNotifier<int>(0);int get _index => _at.value;- static const _last = 6;+ int get _last => _slow ? 7 : 6;final Map<String, Set<String>> _places = {};+ final _frames = <FrameTiming>[];+ bool _slow = false;+ bool _probing = false;+ bool _blur = false;+ bool _motion = false;++ @override+ void initState() {+ super.initState();+ if (fit.lowEndAsked || !fit.blurOn) return;+ DeviceKind.isLowEnd().then((low) {+ if (low) _markSlow();+ });+ _probing = true;+ SchedulerBinding.instance.addTimingsCallback(_timings);+ }++ void _timings(List<FrameTiming> list) {+ _frames.addAll(list);+ if (_frames.length < 45) return;+ _stopProbe();+ final heavy = _frames.where((f) => (f.buildDuration + f.rasterDuration).inMilliseconds > 24).length;+ if (heavy > _frames.length * 0.25) _markSlow();+ }++ void _stopProbe() {+ if (!_probing) return;+ _probing = false;+ SchedulerBinding.instance.removeTimingsCallback(_timings);+ }++ void _markSlow() {+ if (!mounted || _slow) return;+ _stopProbe();+ setState(() => _slow = true);+ }@overridevoid dispose() {+ _stopProbe();_page.dispose();_at.dispose();_name.dispose();@@ -60,6 +100,12 @@ class _OnboardingScreenState extends State<OnboardingScreen> {if (id.isNotEmpty) first ??= id;}if (first != null && fit.activePlaceId != first) fit.setActivePlace(first);+ if (_slow) {+ fit.setPerfLevel(_blur ? 'balanced' : 'lite');+ fit.setBlur(_blur);+ fit.setCalmMotion(!_motion);+ fit.markLowEndAsked();+ }fit.completeOnboarding();}@@ -157,6 +203,7 @@ class _OnboardingScreenState extends State<OnboardingScreen> {_bodyStep(gc),_goalStep(gc),_placeStep(gc),+ if (_slow) _speedStep(gc),])RepaintBoundary(child: page),],@@ -185,7 +232,7 @@ class _OnboardingScreenState extends State<OnboardingScreen> {child: AnimatedContainer(duration: const Duration(milliseconds: 280),curve: Curves.easeOutCubic,- margin: const EdgeInsets.only(right: 6),+ margin: const EdgeInsetsDirectional.only(end: 6),height: 3,decoration: BoxDecoration(color: i <= _index ? gc.text : gc.bgRaised2,@@ -223,7 +270,7 @@ class _OnboardingScreenState extends State<OnboardingScreen> {child: Container(width: 56,height: 56,- margin: const EdgeInsets.only(right: 12),+ margin: const EdgeInsetsDirectional.only(end: 12),decoration: BoxDecoration(color: gc.bgRaised, shape: BoxShape.circle),child: Icon(PhosphorIconsBold.arrowLeft, size: 18, color: gc.textSecondary),),@@ -267,7 +314,7 @@ class _OnboardingScreenState extends State<OnboardingScreen> {}(),const SizedBox(height: 22),],- _in(0, Padding(padding: const EdgeInsets.only(left: 4), child: _label(gc, t.onbStep(step, _last)))),+ _in(0, Padding(padding: const EdgeInsetsDirectional.only(start: 4), child: _label(gc, t.onbStep(step, _last)))),const SizedBox(height: 10),_in(1,@@ -315,7 +362,7 @@ class _OnboardingScreenState extends State<OnboardingScreen> {}Widget _rowIcon(GymColors gc, IconData icon, {Color? color}) => Padding(- padding: const EdgeInsets.only(right: 14),+ padding: const EdgeInsetsDirectional.only(end: 14),child: SizedBox(width: 22, child: Icon(icon, size: 19, color: color ?? gc.textSecondary)),);@@ -736,6 +783,19 @@ class _OnboardingScreenState extends State<OnboardingScreen> {'outdoors': PhosphorIconsRegular.tree,};+ Widget _speedStep(GymColors gc) {+ return _step(+ gc,+ step: 7,+ title: t.onbSpeedTitle,+ why: t.onbSpeedWhy,+ child: SpeedPanel(footer: t.onbSpeedLater, rows: [+ (t.blurSetting, t.onbSpeedBlurHint, _blur, () => setState(() => _blur = !_blur)),+ (t.onbSpeedMotion, t.onbSpeedMotionHint, _motion, () => setState(() => _motion = !_motion)),+ ]),+ );+ }+Widget _placeStep(GymColors gc) {return _step(gc,@@ -790,7 +850,7 @@ class _OnboardingScreenState extends State<OnboardingScreen> {for (final preset in kPlacePresets)if (_places[preset] case final gear?) ...[Padding(- padding: const EdgeInsets.only(left: 4),+ padding: const EdgeInsetsDirectional.only(start: 4),child: _label(gc,_places.length > 1diff --git a/lib/services/device_kind.dart b/lib/services/device_kind.dartindex 409496b..bd84090 100644--- a/lib/services/device_kind.dart+++ b/lib/services/device_kind.dart@@ -8,7 +8,11 @@ class DeviceKind {static const _channel = MethodChannel('gymmane/device');+ @visibleForTesting+ static bool? lowEndOverride;+static Future<bool> isLowEnd() async {+ if (lowEndOverride case final forced?) return forced;if (kIsWeb || !Platform.isAndroid) return false;try {return await _channel.invokeMethod<bool>('isLowEnd') ?? false;@@ -17,6 +21,22 @@ class DeviceKind {}}+ static Future<double> maxRefresh() async {+ if (kIsWeb || !Platform.isAndroid) return 60;+ try {+ return await _channel.invokeMethod<double>('maxRefresh') ?? 60;+ } catch (_) {+ return 60;+ }+ }++ static Future<void> setHighRefresh(bool on) async {+ if (kIsWeb || !Platform.isAndroid) return;+ try {+ await _channel.invokeMethod<void>('setHighRefresh', {'on': on});+ } catch (_) {}+ }+static Future<bool> isWatch() async {if (kIsWeb || !Platform.isAndroid) return false;try {diff --git a/lib/widgets/speed_panel.dart b/lib/widgets/speed_panel.dartnew file mode 100644index 0000000..f8ff3d1--- /dev/null+++ b/lib/widgets/speed_panel.dart@@ -0,0 +1,233 @@+import 'dart:ui' as ui;++import 'package:flutter/material.dart';+import 'package:flutter/services.dart';++import '../theme/app_colors.dart';+import '../theme/app_theme.dart';+import 'ui_kit.dart';++class SpeedPanel extends StatelessWidget {+ const SpeedPanel({super.key, required this.rows, this.footer});++ final List<(String label, String hint, bool on, VoidCallback onTap)> rows;+ final String? footer;++ @override+ Widget build(BuildContext context) {+ final gc = context.gc;+ final blur = rows.isNotEmpty && rows.first.$3;+ final motion = rows.length > 1 && rows[1].$3;+ return Container(+ padding: const EdgeInsets.fromLTRB(14, 14, 14, 14),+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(28)),+ child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [+ Expanded(+ flex: 11,+ child: Column(children: [+ for (final (i, (label, hint, on, tap)) in rows.indexed) ...[+ if (i > 0) const SizedBox(height: 8),+ Pressable(+ scale: 0.97,+ onTap: () {+ HapticFeedback.selectionClick();+ tap();+ },+ child: Container(+ padding: const EdgeInsets.fromLTRB(14, 12, 12, 14),+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(16)),+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [+ Row(children: [+ Expanded(+ child: Text(label,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(13.5, weight: FontWeight.w700, color: on ? gc.text : gc.textSecondary)),+ ),+ const SizedBox(width: 6),+ TinySwitch(on: on),+ ]),+ const SizedBox(height: 6),+ Text(hint, style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary, height: 1.35)),+ ]),+ ),+ ),+ ],+ if (footer != null) ...[+ const SizedBox(height: 12),+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 4),+ child: Text(footer!,+ style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary, height: 1.35)),+ ),+ ],+ ]),+ ),+ const SizedBox(width: 12),+ Expanded(flex: 9, child: AspectRatio(aspectRatio: 0.56, child: _SpeedSketch(blur: blur, motion: motion))),+ ]),+ );+ }+}++class _SpeedSketch extends StatefulWidget {+ const _SpeedSketch({required this.blur, required this.motion});++ final bool blur;+ final bool motion;++ @override+ State<_SpeedSketch> createState() => _SpeedSketchState();+}++class _SpeedSketchState extends State<_SpeedSketch> with SingleTickerProviderStateMixin {+ late final AnimationController _open = AnimationController(+ vsync: this,+ duration: const Duration(milliseconds: 520),+ value: 1,+ );++ @override+ void didUpdateWidget(_SpeedSketch old) {+ super.didUpdateWidget(old);+ if (old.blur == widget.blur && old.motion == widget.motion) return;+ if (widget.motion) {+ _open.forward(from: 0);+ } else {+ _open.value = 1;+ }+ }++ @override+ void dispose() {+ _open.dispose();+ super.dispose();+ }++ Widget _bar(double w, double h, Color color) => Container(+ width: w,+ height: h,+ decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(h)),+ );++ Widget _home(GymColors gc) {+ final soft = gc.text.withValues(alpha: 0.22);+ Widget box(double h, Widget child, {Color? color}) => Container(+ height: h,+ margin: const EdgeInsets.only(bottom: 6),+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),+ decoration: BoxDecoration(color: color ?? gc.bgRaised, borderRadius: BorderRadius.circular(10)),+ child: child,+ );+ return Container(+ color: gc.bg,+ padding: const EdgeInsets.fromLTRB(9, 12, 9, 0),+ child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [+ Align(alignment: Alignment.centerLeft, child: _bar(40, 5, soft)),+ const SizedBox(height: 9),+ box(+ 58,+ Column(crossAxisAlignment: CrossAxisAlignment.start, children: [+ _bar(46, 6, gc.text.withValues(alpha: 0.7)),+ const SizedBox(height: 5),+ _bar(30, 4, soft),+ const Spacer(),+ _bar(double.infinity, 11, gc.text),+ ]),+ color: gc.bgRaised2,+ ),+ box(+ 26,+ Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [+ for (var i = 0; i < 7; i++)+ Container(+ width: 9,+ height: 9,+ decoration: BoxDecoration(shape: BoxShape.circle, color: i > 2 && i < 6 ? gc.text : gc.bgRaised2),+ ),+ ]),+ ),+ Row(children: [+ for (final c in [gc.accent, gc.sage]) ...[+ if (c == gc.sage) const SizedBox(width: 6),+ Expanded(+ child: Container(+ height: 40,+ decoration: BoxDecoration(color: c.withValues(alpha: 0.75), borderRadius: BorderRadius.circular(10)),+ ),+ ),+ ],+ ]),+ const SizedBox(height: 6),+ Row(children: [+ for (var i = 0; i < 3; i++) ...[+ if (i > 0) const SizedBox(width: 5),+ Expanded(child: box(30, const SizedBox.shrink())),+ ],+ ]),+ ]),+ );+ }++ Widget _sheet(GymColors gc) => Padding(+ padding: const EdgeInsets.fromLTRB(10, 7, 10, 10),+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [+ Center(child: _bar(18, 3, gc.text.withValues(alpha: 0.3))),+ const SizedBox(height: 10),+ _bar(54, 6, gc.text.withValues(alpha: 0.8)),+ const SizedBox(height: 6),+ _bar(36, 4, gc.text.withValues(alpha: 0.3)),+ const Spacer(),+ _bar(double.infinity, 13, gc.text),+ ]),+ );++ @override+ Widget build(BuildContext context) {+ final gc = context.gc;+ final blur = widget.blur;+ return ExcludeSemantics(+ child: ClipRRect(+ borderRadius: BorderRadius.circular(20),+ child: ColoredBox(+ color: Colors.black,+ child: AnimatedBuilder(+ animation: _open,+ builder: (context, _) {+ final v = Curves.easeOutCubic.transform(_open.value);+ return LayoutBuilder(builder: (context, box) {+ final sheetH = box.maxHeight * 0.48;+ final page = Transform.scale(+ scale: 1 - (blur ? 0.06 : 0.03) * v,+ child: ClipRRect(borderRadius: BorderRadius.circular(16 * v), child: _home(gc)),+ );+ return Stack(children: [+ Positioned.fill(+ child: blur+ ? ImageFiltered(imageFilter: ui.ImageFilter.blur(sigmaX: 2.5 * v, sigmaY: 2.5 * v), child: page)+ : Opacity(opacity: 1 - 0.35 * v, child: page),+ ),+ Positioned(+ left: 0,+ right: 0,+ bottom: -sheetH * (1 - v),+ height: sheetH,+ child: ClipRRect(+ borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),+ child: blur+ ? BackdropFilter(+ filter: ui.ImageFilter.blur(sigmaX: 9, sigmaY: 9),+ child: ColoredBox(color: gc.bgRaised.withValues(alpha: 0.55), child: _sheet(gc)),+ )+ : ColoredBox(color: gc.bgRaised2, child: _sheet(gc)),+ ),+ ),+ ]);+ });+ },+ ),+ ),+ ),+ );+ }+}