import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../ui/motion/animation_speed.dart'; import '../../ui/motion/quick_switch_animation.dart'; import 'settings_quick_switch_control.dart'; import 'settings_group.dart'; import 'settings_theme.dart'; class SettingsAnimationSection extends StatelessWidget { const SettingsAnimationSection({ super.key, required this.controller, this.quickSwitchController, }); final AnimationSpeedController controller; final QuickSwitchAnimationController? quickSwitchController; @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: 'Animations', 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')], ), ], ), ), SettingsGroupItem( child: SettingsQuickSwitchControl( controller: quickSwitchController ?? QuickSwitchAnimationController.instance, ), ), ], ); }, ); }