83 lines
2.7 KiB
Dart
83 lines
2.7 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../../ui/motion/quick_switch_animation.dart';
|
|
import 'settings_theme.dart';
|
|
import 'quick_switch_preview.dart';
|
|
|
|
class SettingsQuickSwitchControl extends StatelessWidget {
|
|
const SettingsQuickSwitchControl({super.key, required this.controller});
|
|
final QuickSwitchAnimationController controller;
|
|
|
|
Future<void> _choose(BuildContext context) async {
|
|
final choice = await showCupertinoModalPopup<QuickSwitchAnimation>(
|
|
context: context,
|
|
builder: (context) => CupertinoActionSheet(
|
|
title: const Text('Quick switch animation'),
|
|
actions: [
|
|
for (final animation in QuickSwitchAnimation.values)
|
|
CupertinoActionSheetAction(
|
|
isDefaultAction: animation == controller.value,
|
|
onPressed: () => Navigator.pop(context, animation),
|
|
child: Text(animation.label),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
),
|
|
);
|
|
if (choice != null) await controller.setAnimation(choice);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => ListenableBuilder(
|
|
listenable: controller,
|
|
builder: (context, _) => Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(
|
|
'Quick switch animation',
|
|
style: settingsTextStyle(context, title: true),
|
|
),
|
|
if (usesCupertinoControls(context))
|
|
CupertinoButton(
|
|
onPressed: () => unawaited(_choose(context)),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(controller.value.label),
|
|
const SizedBox(width: 8),
|
|
const Icon(CupertinoIcons.chevron_down),
|
|
],
|
|
),
|
|
)
|
|
else
|
|
DropdownButton<QuickSwitchAnimation>(
|
|
value: controller.value,
|
|
isExpanded: true,
|
|
items: [
|
|
for (final animation in QuickSwitchAnimation.values)
|
|
DropdownMenuItem(
|
|
value: animation,
|
|
child: Text(animation.label),
|
|
),
|
|
],
|
|
onChanged: (value) {
|
|
if (value != null) unawaited(controller.setAnimation(value));
|
|
},
|
|
),
|
|
Text(controller.value.description),
|
|
const SizedBox(height: 8),
|
|
QuickSwitchPreview(animation: controller.value),
|
|
if (controller.saveFailed)
|
|
Text(
|
|
'Could not save; applies until reload.',
|
|
style: TextStyle(color: settingsErrorColor(context)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|