118 lines
3.8 KiB
Dart
118 lines
3.8 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../ui/theme/app_design.dart';
|
|
import '../../ui/theme/app_design_controller.dart';
|
|
import 'settings_group.dart';
|
|
import 'settings_theme.dart';
|
|
|
|
const designSectionTitle = 'Design';
|
|
const designSectionFooter =
|
|
'Saved on this device only and applied at once. Light and dark follow '
|
|
'the system under every design. Terminal uses its monospace font '
|
|
'instead of the Font choice below; Paper keeps that font for the '
|
|
'interface and sets reading text in its own serif.';
|
|
const designSaveFailedText =
|
|
'Not saved on this device; it applies until reload.';
|
|
|
|
ValueKey<String> settingsDesignKey(AppDesign design) =>
|
|
ValueKey<String>('settings-design-${design.id}');
|
|
|
|
/// The device's app-wide design: one radio row per [AppDesign], each with a
|
|
/// one-line summary. A choice applies at once, without a restart.
|
|
class SettingsDesignSection extends StatelessWidget {
|
|
const SettingsDesignSection({super.key, required this.controller});
|
|
|
|
final AppDesignController controller;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => ListenableBuilder(
|
|
listenable: controller,
|
|
builder: (context, _) => RadioGroup<AppDesign>(
|
|
groupValue: controller.design,
|
|
onChanged: (design) {
|
|
if (design != null) unawaited(controller.select(design));
|
|
},
|
|
child: SettingsGroup(
|
|
title: designSectionTitle,
|
|
footer: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const Text(designSectionFooter),
|
|
if (controller.saveFailed)
|
|
Text(
|
|
designSaveFailedText,
|
|
style: TextStyle(color: settingsErrorColor(context)),
|
|
),
|
|
],
|
|
),
|
|
children: [
|
|
for (final design in AppDesign.values)
|
|
RadioListTile<AppDesign>(
|
|
key: settingsDesignKey(design),
|
|
value: design,
|
|
title: Text(design.label),
|
|
subtitle: Text(design.description),
|
|
secondary: DesignSwatchPreview(
|
|
swatch: design.swatch(Theme.of(context).brightness),
|
|
lines: design.swatchLines,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// A design's small preview in the picker: its page with [lines] lines of
|
|
/// its ink (the last one short) and a dot of its accent, framed by a
|
|
/// hairline. A dense design draws more, tighter lines in the same page.
|
|
class DesignSwatchPreview extends StatelessWidget {
|
|
const DesignSwatchPreview({super.key, required this.swatch, this.lines = 2});
|
|
|
|
final DesignSwatch swatch;
|
|
final int lines;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => ExcludeSemantics(
|
|
child: Container(
|
|
width: 48,
|
|
height: 32,
|
|
decoration: BoxDecoration(
|
|
color: swatch.page,
|
|
borderRadius: const BorderRadius.all(Radius.circular(6)),
|
|
border: Border.all(color: Theme.of(context).colorScheme.outlineVariant),
|
|
),
|
|
padding: const EdgeInsets.all(8),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
for (var line = 1; line < lines; line += 1)
|
|
Container(height: lines > 2 ? 1 : 2, color: swatch.ink),
|
|
FractionallySizedBox(
|
|
widthFactor: 0.6,
|
|
child: Container(height: lines > 2 ? 1 : 2, color: swatch.ink),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 4),
|
|
Container(
|
|
width: 6,
|
|
height: 6,
|
|
decoration: BoxDecoration(
|
|
color: swatch.accent,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|