Merge branch 'feature/animation-speed'
This commit is contained in:
@@ -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,
|
||||
),
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# Animation speed
|
||||
|
||||
Settings offers a device-local 0.5×–2.0× animation speed slider in 0.1 steps,
|
||||
with normal speed at 1.0× and a Reset action. It applies immediately and persists
|
||||
at the end of a drag. A failed save is reported without hiding the active choice.
|
||||
|
||||
`AnimationSpeedController` restores at bootstrap before the first app frame and
|
||||
sets Flutter scheduler `timeDilation = 1 / speed`. Scheduler timestamps scale
|
||||
all ticker-based animations, native routes, implicit transitions and springs.
|
||||
Do not divide Motion durations again. `Timer`/`Future` delays, networking and
|
||||
retry clocks remain real time. Existing reduce-motion paths remain authoritative.
|
||||
The factor is not part of server/workspace settings and survives server changes.
|
||||
|
||||
Checks: watchdog motion tests and native Material/Cupertino slider interaction
|
||||
tests; clean analyzer; fixture web build and Settings browser interaction captures.
|
||||
No device verification was performed.
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_animation_section.dart';
|
||||
import 'package:pipelines_app/ui/motion/animation_speed.dart';
|
||||
|
||||
class _Store implements AnimationSpeedStore {
|
||||
double? saved;
|
||||
@override
|
||||
Future<double?> load() async => saved;
|
||||
@override
|
||||
Future<bool> save(double speed) async {
|
||||
saved = speed;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
tearDown(() => timeDilation = 1);
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'native slider updates global speed and Reset restores normal ($cupertino)',
|
||||
(tester) async {
|
||||
final store = _Store();
|
||||
final controller = AnimationSpeedController(store: store);
|
||||
final section = SettingsAnimationSection(controller: controller);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: section))
|
||||
: MaterialApp(home: Scaffold(body: section)),
|
||||
);
|
||||
if (cupertino) {
|
||||
final slider = tester.widget<CupertinoSlider>(
|
||||
find.byType(CupertinoSlider),
|
||||
);
|
||||
slider.onChanged!(1.8);
|
||||
slider.onChangeEnd!(1.8);
|
||||
} else {
|
||||
final slider = tester.widget<Slider>(find.byType(Slider));
|
||||
slider.onChanged!(1.8);
|
||||
slider.onChangeEnd!(1.8);
|
||||
}
|
||||
await tester.pump();
|
||||
expect(find.text('1.8×'), findsWidgets);
|
||||
expect(timeDilation, closeTo(1 / 1.8, 0.001));
|
||||
expect(store.saved, 1.8);
|
||||
await tester.tap(find.text('Reset'));
|
||||
await tester.pump();
|
||||
expect(controller.speed, 1);
|
||||
expect(timeDilation, 1);
|
||||
expect(store.saved, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/motion/animation_speed.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||
|
||||
class _Store implements AnimationSpeedStore {
|
||||
double? value;
|
||||
bool fail = false;
|
||||
Completer<double?>? pending;
|
||||
@override
|
||||
Future<double?> load() async => pending == null ? value : pending!.future;
|
||||
@override
|
||||
Future<bool> save(double value) async {
|
||||
this.value = value;
|
||||
return !fail;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
tearDown(() => timeDilation = 1);
|
||||
test(
|
||||
'device preference restores speed, clamps values, resets and reports save failure',
|
||||
() async {
|
||||
final store = _Store()..value = 2;
|
||||
final controller = AnimationSpeedController(store: store);
|
||||
await controller.restore();
|
||||
expect(controller.speed, 2);
|
||||
expect(timeDilation, 0.5);
|
||||
controller.setSpeed(0.1);
|
||||
expect(controller.speed, 0.5);
|
||||
expect(timeDilation, 2);
|
||||
await controller.save();
|
||||
expect(store.value, 0.5);
|
||||
store.fail = true;
|
||||
await controller.save();
|
||||
expect(controller.saveFailed, isTrue);
|
||||
store.fail = false;
|
||||
await controller.reset();
|
||||
expect(timeDilation, 1);
|
||||
expect(store.value, 1);
|
||||
expect(controller.saveFailed, isFalse);
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
test(
|
||||
'late restore cannot overwrite a newer choice and invalid values are ignored',
|
||||
() async {
|
||||
final store = _Store()..pending = Completer<double?>();
|
||||
final controller = AnimationSpeedController(store: store);
|
||||
final restore = controller.restore();
|
||||
controller.setSpeed(1.5);
|
||||
store.pending!.complete(0.5);
|
||||
await restore;
|
||||
expect(controller.speed, 1.5);
|
||||
controller.setSpeed(double.nan);
|
||||
expect(controller.speed, 1.5);
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
testWidgets(
|
||||
'animation clock changes ticker speed while wall timers and reduced motion stay independent',
|
||||
(tester) async {
|
||||
final controller = AnimationSpeedController(store: _Store());
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
final animation = AnimationController(
|
||||
vsync: tester,
|
||||
duration: const Duration(seconds: 1),
|
||||
);
|
||||
|
||||
controller.setSpeed(2);
|
||||
animation.forward();
|
||||
await tester.pump();
|
||||
var elapsed = false;
|
||||
final timer = Timer(
|
||||
const Duration(milliseconds: 250),
|
||||
() => elapsed = true,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(animation.value, closeTo(0.5, 0.02));
|
||||
expect(elapsed, isTrue);
|
||||
timer.cancel();
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(disableAnimations: true),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
expect(Motion.of(context, Motion.standard), Duration.zero);
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
animation.dispose();
|
||||
controller.dispose();
|
||||
timeDilation = 1;
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user