Merge branch 'feature/animation-speed'

This commit is contained in:
2026-11-07 02:46:38 +00:00
8 changed files with 375 additions and 0 deletions
+3
View File
@@ -8,6 +8,7 @@ import 'server_endpoint.dart';
import '../features/settings/settings_store.dart';
import '../ui/theme/app_font_controller.dart';
import '../ui/theme/app_font_licenses.dart';
import '../ui/motion/animation_speed.dart';
/// Native builds must supply their server explicitly; there is no baked host.
const configuredServerUrl = String.fromEnvironment('PIPELINES_SERVER_URL');
@@ -55,10 +56,12 @@ Future<void> runPipelinesApp({
registerAppFontLicenses();
// The device's chosen font loads beside the session; a slow download does
// not hold the first frame, and applies when it lands.
final animationSpeed = AnimationSpeedController.instance.restore();
final font = AppFontController.instance.restore(wait: appFontStartupWait);
// A phone behind the web login reconnects with its kept session.
await ServerSession.load();
await font;
await animationSpeed;
final server = await resolveLaunchServer(
base: base,
configured: configured,
@@ -0,0 +1,90 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/motion/animation_speed.dart';
import 'settings_group.dart';
import 'settings_theme.dart';
class SettingsAnimationSection extends StatelessWidget {
const SettingsAnimationSection({super.key, required this.controller});
final AnimationSpeedController controller;
@override
Widget build(BuildContext context) => ListenableBuilder(
listenable: controller,
builder: (context, _) {
final cupertino = usesCupertinoControls(context);
final speed = controller.speed;
final label = '${speed.toStringAsFixed(1)}×';
final reset = speed == 1 ? null : () => unawaited(controller.reset());
return SettingsGroup(
title: 'Animation speed',
footer: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Saved on this device. Higher is faster. Default 1.0×. Respects reduced motion.',
),
if (controller.saveFailed)
Text(
'Could not save; applies until reload.',
style: TextStyle(color: settingsErrorColor(context)),
),
],
),
children: [
SettingsGroupItem(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(label, style: settingsTextStyle(context, title: true)),
cupertino
? CupertinoButton(
onPressed: reset,
child: const Text('Reset'),
)
: TextButton(
onPressed: reset,
child: const Text('Reset'),
),
],
),
Semantics(
label: 'Animation speed',
child: cupertino
? CupertinoSlider(
value: speed,
min: minAnimationSpeed,
max: maxAnimationSpeed,
divisions: 15,
onChanged: controller.setSpeed,
onChangeEnd: (_) => unawaited(controller.save()),
)
: Slider(
value: speed,
min: minAnimationSpeed,
max: maxAnimationSpeed,
divisions: 15,
label: label,
semanticFormatterCallback: (value) =>
'${value.toStringAsFixed(1)} times',
onChanged: controller.setSpeed,
onChangeEnd: (_) => unawaited(controller.save()),
),
),
const Wrap(
alignment: WrapAlignment.spaceBetween,
children: [Text('0.5× · Slower'), Text('2.0× · Faster')],
),
],
),
),
],
);
},
);
}
@@ -11,6 +11,8 @@ import 'default_endpoint.dart';
import 'settings_controller.dart';
import 'settings_controls.dart';
import 'settings_font_section.dart';
import 'settings_animation_section.dart';
import '../../ui/motion/animation_speed.dart';
import '../../ui/theme/app_font_controller.dart';
import 'settings_group.dart';
import 'storage/settings_storage_section.dart';
@@ -58,10 +60,12 @@ class SettingsScreen extends StatefulWidget {
this.deliveryService,
this.deliveryServiceController,
this.fonts,
this.animationSpeed,
});
/// The device's interface font; defaults to the app's shared controller.
final AppFontController? fonts;
final AnimationSpeedController? animationSpeed;
/// Android background delivery; hidden when absent or unsupported.
final NotificationServiceBridge? deliveryService;
@@ -204,6 +208,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
_single('Server', SettingsHealthSection(gateway: widget.client)),
// A device-local choice: a browser and a phone keep their own.
SettingsAnimationSection(
controller:
widget.animationSpeed ?? AnimationSpeedController.instance,
),
SettingsFontSection(
controller: widget.fonts ?? AppFontController.instance,
),
+97
View File
@@ -0,0 +1,97 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
import 'package:shared_preferences/shared_preferences.dart';
const animationSpeedKey = 'pipelines.animation-speed.v1';
const minAnimationSpeed = 0.5;
const maxAnimationSpeed = 2.0;
abstract interface class AnimationSpeedStore {
Future<double?> load();
Future<bool> save(double speed);
}
class SharedAnimationSpeedStore implements AnimationSpeedStore {
const SharedAnimationSpeedStore();
@override
Future<double?> load() async {
try {
return (await SharedPreferences.getInstance()).getDouble(
animationSpeedKey,
);
} catch (_) {
return null;
}
}
@override
Future<bool> save(double speed) async {
try {
return await (await SharedPreferences.getInstance()).setDouble(
animationSpeedKey,
speed,
);
} catch (_) {
return false;
}
}
}
/// A device-local animation clock. Larger factors play animations faster.
///
/// Flutter divides scheduler frame timestamps by timeDilation, including
/// native routes, implicit animations and physics. Its setter resets the epoch
/// to preserve continuity for in-flight animations. Values below one are valid.
/// Durations in Motion must NOT also be scaled. Real timers, networking and
/// retry delays keep wall-clock time; existing reduced-motion handling remains.
class AnimationSpeedController extends ChangeNotifier {
AnimationSpeedController({AnimationSpeedStore? store})
: _store = store ?? const SharedAnimationSpeedStore();
static final instance = AnimationSpeedController();
final AnimationSpeedStore _store;
double _speed = 1;
int _revision = 0;
bool _disposed = false;
bool saveFailed = false;
double get speed => _speed;
Future<void> restore() async {
final revision = _revision;
final value = await _store.load();
if (_disposed ||
revision != _revision ||
value == null ||
!value.isFinite) {
return;
}
setSpeed(value);
}
void setSpeed(double value) {
if (_disposed || !value.isFinite) return;
_revision++;
_speed = value.clamp(minAnimationSpeed, maxAnimationSpeed);
saveFailed = false;
timeDilation = 1 / _speed;
notifyListeners();
}
Future<void> save() async {
final revision = _revision;
final saved = await _store.save(_speed);
if (_disposed || revision != _revision) return;
saveFailed = !saved;
notifyListeners();
}
Future<void> reset() async {
setSpeed(1);
await save();
}
@override
void dispose() {
_disposed = true;
super.dispose();
}
}
+3
View File
@@ -1,5 +1,8 @@
import 'package:flutter/widgets.dart';
/// Durations stay unscaled: AnimationSpeedController adjusts the global
/// scheduler clock once, including native routes and implicit animations.
///
/// Short, quiet motion shared by the app: opening and closing sections,
/// counts and statuses changing, live items arriving. Every duration drops
/// to zero when the system asks for reduced motion.