Files
pipelines/app/lib/features/settings/settings_scale_section.dart
T
alan 3933ff980c Remove Cupertino settings branches
Keep the Material settings implementation while preserving public Cupertino parameters for later cleanup. Narrow settings tests to the Material-only behavior.
2026-11-11 05:21:30 +00:00

101 lines
3.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:async';
import 'package:flutter/material.dart';
import '../../ui/scale/ui_scale.dart';
import 'settings_group.dart';
import 'settings_theme.dart';
/// "Interface size": a 0.5×–2.0× slider for the whole app on this device.
/// The value previews beside the slider while dragging and applies when the
/// drag ends, so the slider does not resize under the pointer.
class SettingsScaleSection extends StatefulWidget {
const SettingsScaleSection({super.key, this.controller});
final UiScaleController? controller;
@override
State<SettingsScaleSection> createState() => _SettingsScaleSectionState();
}
class _SettingsScaleSectionState extends State<SettingsScaleSection> {
double? _draft;
UiScaleController get _controller =>
widget.controller ?? UiScaleController.instance;
void _apply(double value) {
setState(() => _draft = null);
_controller.setScale(value);
unawaited(_controller.save());
}
@override
Widget build(BuildContext context) => ListenableBuilder(
listenable: _controller,
builder: (context, _) {
final value = _draft ?? _controller.scale;
final label = '${value.toStringAsFixed(1)}×';
final reset = _controller.scale == 1 && _draft == null
? null
: () {
setState(() => _draft = null);
unawaited(_controller.reset());
};
void drag(double next) => setState(() => _draft = next);
return SettingsGroup(
title: 'Interface size',
footer: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Scales text, icons and spacing everywhere on this device. '
'Applies when you let go. Default 1.0×.',
),
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)),
TextButton(onPressed: reset, child: const Text('Reset')),
],
),
Semantics(
label: 'Interface size',
child: Slider(
key: const Key('settings-ui-scale'),
value: value,
min: minUiScale,
max: maxUiScale,
divisions: 15,
label: label,
semanticFormatterCallback: (v) =>
'${v.toStringAsFixed(1)} times',
onChanged: drag,
onChangeEnd: _apply,
),
),
const Wrap(
alignment: WrapAlignment.spaceBetween,
children: [Text('0.5× · Smaller'), Text('2.0× · Larger')],
),
],
),
),
],
);
},
);
}