Files
pipelines/app/lib/features/settings/settings_scale_section.dart
T
alan bb2adcc182 Add an interface size setting (0.5x to 2x)
Settings > Appearance > Interface size scales every dimension, text, icon
and dialog on this device. The app lays out in a smaller or larger viewport
and paints it scaled to the window, so hit testing and layout stay
consistent; the value is saved per device and applies when the slider is
released.
2026-11-09 12:56:42 +00:00

121 lines
4.2 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/cupertino.dart';
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 cupertino = usesCupertinoControls(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)),
cupertino
? CupertinoButton(
onPressed: reset,
child: const Text('Reset'),
)
: TextButton(
onPressed: reset,
child: const Text('Reset'),
),
],
),
Semantics(
label: 'Interface size',
child: cupertino
? CupertinoSlider(
key: const Key('settings-ui-scale'),
value: value,
min: minUiScale,
max: maxUiScale,
divisions: 15,
onChanged: drag,
onChangeEnd: _apply,
)
: 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')],
),
],
),
),
],
);
},
);
}