feat: initial Cutdex application
Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,31 @@
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
/pubspec.lock
|
||||
**/doc/api/
|
||||
.dart_tool/
|
||||
.flutter-plugins-dependencies
|
||||
/build/
|
||||
/coverage/
|
||||
@@ -0,0 +1,10 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
|
||||
version:
|
||||
revision: "6a19cca56475dbfba1478ee68d7bd0c2ef891da1"
|
||||
channel: "stable"
|
||||
|
||||
project_type: package
|
||||
@@ -0,0 +1,22 @@
|
||||
# cutdex_ui
|
||||
|
||||
Cutdex workspace 内部 Flutter 包,维护通用组件与基础视觉主题,暂不发布。
|
||||
|
||||
- `theme.dart`:主题、语义颜色、间距与控件尺寸。
|
||||
- `widgets.dart`:菜单、选择框、对话框、输入控件、标签页、面板、下载进度、滚动渐隐等。
|
||||
- `cutdex_ui.dart`:上述两个入口。
|
||||
|
||||
组件通过参数接收文本、数据与回调;应用本地化与项目状态由调用方提供。选择框的空列表文案使用 `emptyLabel`,可搜索选择框同时传入 `searchHint`。对话框默认关闭提示由 Flutter 的 Material 本地化提供,也可传入 `closeLabel`。
|
||||
|
||||
`WorkspacePanel` 通过参数接收标题、控件与内容;`ResourceDownloadProgress` 接收字节数、速度与调用方提供的状态文案,`formatResourceBytes` 使用十进制字节单位。资源目录、下载任务与业务对话框由应用维护。
|
||||
|
||||
原生菜单通过 `cutdex_native` 展示,无法展示时回退到 Flutter 菜单。时间线与编辑器的业务样式由应用维护。
|
||||
|
||||
在应用根目录执行 `flutter pub get`;在本包目录执行:
|
||||
|
||||
```sh
|
||||
dart run build_runner build
|
||||
flutter test
|
||||
```
|
||||
|
||||
生成的 Freezed 文件随源码提交。测试维护在本包 `test/`,应用接线测试保留在应用中。
|
||||
@@ -0,0 +1,8 @@
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
analyzer:
|
||||
exclude:
|
||||
- build/**
|
||||
language:
|
||||
strict-casts: true
|
||||
strict-inference: true
|
||||
strict-raw-types: true
|
||||
@@ -0,0 +1,2 @@
|
||||
export 'theme.dart';
|
||||
export 'widgets.dart';
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,20 @@
|
||||
/// Shared compact popover/menu scale, based on the Codex project picker.
|
||||
abstract final class AppMenuMetrics {
|
||||
static const modeMenuWidth = 240.0;
|
||||
static const descriptionRowHeight = 56.0;
|
||||
static const descriptionVerticalPadding = 10.0;
|
||||
static const titleFontSize = 14.0;
|
||||
static const titleLineHeight = 20.0;
|
||||
static const descriptionFontSize = 12.0;
|
||||
static const descriptionLineHeight = 16.0;
|
||||
static const radius = 20.0;
|
||||
static const itemRadius = 12.0;
|
||||
static const gutter = 6.0;
|
||||
static const separatorVerticalPadding = 4.0;
|
||||
static const rowHeight = 28.0;
|
||||
static const iconSize = 14.0;
|
||||
static const iconGap = 8.0;
|
||||
static const fontSize = 13.0;
|
||||
static const lineHeight = 18.0;
|
||||
static const borderWidth = 0.5;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// Connected action buttons with a shared outline and internal separators.
|
||||
class AppButtonGroup extends StatelessWidget {
|
||||
const AppButtonGroup({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.children,
|
||||
this.expanded = false,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final List<Widget> children;
|
||||
final bool expanded;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final inputBorder = theme.inputDecorationTheme.enabledBorder;
|
||||
final borderRadius = inputBorder is OutlineInputBorder
|
||||
? inputBorder.borderRadius
|
||||
: BorderRadius.circular(AppRadius.large);
|
||||
final height =
|
||||
theme.inputDecorationTheme.constraints?.minHeight ??
|
||||
AppControlSize.input;
|
||||
final fill = theme.inputDecorationTheme.fillColor ?? Colors.transparent;
|
||||
return Semantics(
|
||||
container: true,
|
||||
label: label,
|
||||
child: SizedBox(
|
||||
height: height,
|
||||
child: Container(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
borderRadius: borderRadius,
|
||||
),
|
||||
child: IconButtonTheme(
|
||||
data: IconButtonThemeData(
|
||||
style:
|
||||
IconButton.styleFrom(
|
||||
minimumSize: Size(28, height),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.gap,
|
||||
),
|
||||
shape: const RoundedRectangleBorder(),
|
||||
side: BorderSide.none,
|
||||
foregroundColor: colors.onSurface,
|
||||
hoverColor: colors.onSurface.withValues(alpha: .06),
|
||||
).copyWith(
|
||||
backgroundColor: WidgetStateProperty.resolveWith((states) {
|
||||
if (!states.contains(WidgetState.selected)) return fill;
|
||||
final interacting =
|
||||
states.contains(WidgetState.hovered) ||
|
||||
states.contains(WidgetState.focused) ||
|
||||
states.contains(WidgetState.pressed);
|
||||
return Color.alphaBlend(
|
||||
colors.onSurface.withValues(
|
||||
alpha: interacting ? .10 : .05,
|
||||
),
|
||||
fill,
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: expanded ? MainAxisSize.max : MainAxisSize.min,
|
||||
children: [
|
||||
for (var i = 0; i < children.length; i++) ...[
|
||||
if (i > 0)
|
||||
const VerticalDivider(
|
||||
width: 1,
|
||||
thickness: 1,
|
||||
color: Colors.transparent,
|
||||
),
|
||||
if (expanded) Expanded(child: children[i]) else children[i],
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'app_menu.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// Editable select: typed text filters options, but only a selection changes value.
|
||||
class AppCombobox<T> extends StatefulWidget {
|
||||
const AppCombobox({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.options,
|
||||
required this.onChanged,
|
||||
required this.label,
|
||||
required this.emptyLabel,
|
||||
required this.searchHint,
|
||||
});
|
||||
final T value;
|
||||
final List<AppSelectOption<T>> options;
|
||||
final ValueChanged<T>? onChanged;
|
||||
final String label;
|
||||
final String emptyLabel;
|
||||
final String searchHint;
|
||||
|
||||
@override
|
||||
State<AppCombobox<T>> createState() => _AppComboboxState<T>();
|
||||
}
|
||||
|
||||
class _AppComboboxState<T> extends State<AppCombobox<T>> {
|
||||
final _menu = MenuController();
|
||||
final _focus = FocusNode();
|
||||
final _input = TextEditingController();
|
||||
final _firstOption = GlobalKey();
|
||||
String _query = '';
|
||||
|
||||
String get _selectedLabel =>
|
||||
widget.options
|
||||
.where((option) => option.value == widget.value)
|
||||
.firstOrNull
|
||||
?.label ??
|
||||
'';
|
||||
List<AppSelectOption<T>> get _filtered => widget.options
|
||||
.where(
|
||||
(option) => [
|
||||
option.label,
|
||||
...option.searchTerms,
|
||||
].any((term) => term.toLowerCase().contains(_query.toLowerCase())),
|
||||
)
|
||||
.toList();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_input.text = _selectedLabel;
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant AppCombobox<T> oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.value != widget.value || !_menu.isOpen) {
|
||||
_input.text = _selectedLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focus.dispose();
|
||||
_input.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _open() {
|
||||
if (widget.onChanged == null || _menu.isOpen) return;
|
||||
setState(() => _query = '');
|
||||
_focus.requestFocus();
|
||||
_input.selection = TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: _input.text.length,
|
||||
);
|
||||
_menu.open();
|
||||
}
|
||||
|
||||
void _restore() {
|
||||
_input.text = _selectedLabel;
|
||||
if (mounted) setState(() => _query = '');
|
||||
}
|
||||
|
||||
KeyEventResult _handleKey(FocusNode node, KeyEvent event) {
|
||||
if (event is! KeyDownEvent || widget.onChanged == null) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
if (event.logicalKey == LogicalKeyboardKey.escape && _menu.isOpen) {
|
||||
_menu.close();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
|
||||
if (!_menu.isOpen) {
|
||||
_open();
|
||||
} else {
|
||||
final entry = _firstOption.currentContext;
|
||||
if (entry != null) {
|
||||
FocusTraversalGroup.of(entry)
|
||||
.findFirstFocus(FocusScope.of(entry), ignoreCurrentFocus: true)
|
||||
?.requestFocus();
|
||||
}
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (event.logicalKey == LogicalKeyboardKey.enter && _menu.isOpen) {
|
||||
final first = _filtered.where((option) => option.enabled).firstOrNull;
|
||||
if (first != null) {
|
||||
_menu.close();
|
||||
widget.onChanged!(first.value);
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final width = constraints.hasBoundedWidth ? constraints.maxWidth : 240.0;
|
||||
final filtered = _filtered;
|
||||
return MenuAnchor(
|
||||
controller: _menu,
|
||||
childFocusNode: _focus,
|
||||
consumeOutsideTap: false,
|
||||
crossAxisUnconstrained: false,
|
||||
alignmentOffset: const Offset(0, 4),
|
||||
style: AppMenuStyle.selectPanel(context, minWidth: width).copyWith(
|
||||
maximumSize: const WidgetStatePropertyAll(Size(double.infinity, 320)),
|
||||
),
|
||||
onClose: _restore,
|
||||
menuChildren: [
|
||||
if (filtered.isEmpty) AppMenuLabel(widget.emptyLabel),
|
||||
for (var i = 0; i < filtered.length; i++)
|
||||
Builder(
|
||||
key: i == 0 ? _firstOption : null,
|
||||
builder: (_) {
|
||||
final option = filtered[i];
|
||||
return AppMenuItem(
|
||||
label: option.label,
|
||||
selected: option.value == widget.value,
|
||||
selectOption: true,
|
||||
requestFocusOnHover: false,
|
||||
onPressed: widget.onChanged == null || !option.enabled
|
||||
? null
|
||||
: () => widget.onChanged!(option.value),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
child: Semantics(
|
||||
label: widget.label,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
onKeyEvent: _handleKey,
|
||||
child: Opacity(
|
||||
opacity: widget.onChanged == null ? .5 : 1,
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: AppControlSize.input,
|
||||
),
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
start: AppSpacing.compact,
|
||||
end: AppSpacing.tiny,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.comboboxBackground(context),
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
border: Border.all(color: colors.outlineVariant),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .05),
|
||||
offset: const Offset(0, 1),
|
||||
blurRadius: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _input,
|
||||
focusNode: _focus,
|
||||
enabled: widget.onChanged != null,
|
||||
onTap: _open,
|
||||
onTapAlwaysCalled: true,
|
||||
onChanged: (text) {
|
||||
setState(() => _query = text);
|
||||
if (!_menu.isOpen) _menu.open();
|
||||
},
|
||||
style: theme.textTheme.bodyLarge,
|
||||
decoration: InputDecoration(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: AppControlSize.input - 2,
|
||||
),
|
||||
hintText: widget.searchHint,
|
||||
isDense: true,
|
||||
filled: false,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: AppSpacing.inputVertical - 2,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
errorBorder: InputBorder.none,
|
||||
focusedErrorBorder: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: null,
|
||||
onPressed: widget.onChanged == null
|
||||
? null
|
||||
: () => _menu.isOpen ? _menu.close() : _open(),
|
||||
style: IconButton.styleFrom(
|
||||
overlayColor: Colors.transparent,
|
||||
minimumSize: const Size.square(
|
||||
AppControlSize.input - 2,
|
||||
),
|
||||
padding: const EdgeInsets.all(
|
||||
AppSpacing.inputVertical,
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
icon: Icon(
|
||||
Icons.expand_more,
|
||||
size: 16,
|
||||
color: colors.onSurfaceVariant.withValues(alpha: .5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
Future<T?> showAppDialog<T>({
|
||||
required BuildContext context,
|
||||
required WidgetBuilder builder,
|
||||
}) => showDialog<T>(
|
||||
context: context,
|
||||
barrierColor: Theme.of(context).dialogTheme.barrierColor,
|
||||
animationStyle: const AnimationStyle(duration: Duration(milliseconds: 200)),
|
||||
builder: builder,
|
||||
);
|
||||
|
||||
/// A compact selectable row for dialogs that ask the user to choose an item.
|
||||
class AppDialogOption extends StatelessWidget {
|
||||
const AppDialogOption({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
child: SizedBox(
|
||||
height: 32,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Text(label, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Shared desktop dialog with Codex content, header and footer spacing.
|
||||
class AppDialog extends StatelessWidget {
|
||||
const AppDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.child,
|
||||
this.description,
|
||||
this.header,
|
||||
this.navigation,
|
||||
this.actions = const [],
|
||||
this.width = 420,
|
||||
this.height,
|
||||
this.closeLabel,
|
||||
this.withShadow = true,
|
||||
this.editorHeader = false,
|
||||
this.contentOnly = false,
|
||||
this.showEditorTitle = true,
|
||||
this.editorHeaderHeight = AppControlSize.panelHeader,
|
||||
this.editorHeaderHorizontalPadding = AppSpacing.compact,
|
||||
this.editorContentPadding,
|
||||
this.scrollContent = true,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String? description;
|
||||
final Widget? header;
|
||||
final Widget? navigation;
|
||||
final Widget child;
|
||||
final List<Widget> actions;
|
||||
final double width;
|
||||
final double? height;
|
||||
final String? closeLabel;
|
||||
final bool withShadow;
|
||||
final bool editorHeader;
|
||||
final bool contentOnly;
|
||||
final bool showEditorTitle;
|
||||
final double editorHeaderHeight;
|
||||
final double editorHeaderHorizontalPadding;
|
||||
final EdgeInsets? editorContentPadding;
|
||||
final bool scrollContent;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final dialogTheme = theme.dialogTheme;
|
||||
final shape =
|
||||
dialogTheme.shape ??
|
||||
const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(AppRadius.dialog)),
|
||||
);
|
||||
final radius = shape is RoundedRectangleBorder
|
||||
? shape.borderRadius
|
||||
: const BorderRadius.all(Radius.circular(AppRadius.dialog));
|
||||
return Theme(
|
||||
data: editorHeader || contentOnly
|
||||
? theme
|
||||
: AppTheme.dialogContentTheme(theme),
|
||||
child: Dialog(
|
||||
insetPadding: const EdgeInsets.all(AppSpacing.medium),
|
||||
backgroundColor: Colors.transparent,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
constraints: const BoxConstraints(),
|
||||
clipBehavior: Clip.none,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: radius,
|
||||
// Approximate Tailwind shadow-lg using two Flutter shadows.
|
||||
boxShadow: withShadow
|
||||
? [
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .1),
|
||||
offset: const Offset(0, 10),
|
||||
blurRadius: 15,
|
||||
spreadRadius: -3,
|
||||
),
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .1),
|
||||
offset: const Offset(0, 4),
|
||||
blurRadius: 6,
|
||||
spreadRadius: -4,
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Material(
|
||||
color: dialogTheme.backgroundColor ?? colors.surfaceContainer,
|
||||
shape: shape,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: SizedBox(
|
||||
key: const Key('app-dialog-frame'),
|
||||
width: width,
|
||||
height: height,
|
||||
child: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: contentOnly
|
||||
? EdgeInsets.zero
|
||||
: editorHeader
|
||||
? editorContentPadding ??
|
||||
EdgeInsets.fromLTRB(
|
||||
AppSpacing.medium,
|
||||
editorHeaderHeight + AppSpacing.medium,
|
||||
AppSpacing.medium,
|
||||
AppSpacing.medium,
|
||||
)
|
||||
: const EdgeInsets.all(AppSpacing.large),
|
||||
child: DefaultTextStyle(
|
||||
style:
|
||||
dialogTheme.contentTextStyle ??
|
||||
theme.textTheme.bodyMedium!,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (!editorHeader && !contentOnly)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
end:
|
||||
AppControlSize.headerButton +
|
||||
AppSpacing.gap,
|
||||
),
|
||||
child: Semantics(
|
||||
namesRoute: true,
|
||||
header: true,
|
||||
label: header != null ? title : null,
|
||||
child:
|
||||
header ??
|
||||
Text(
|
||||
title,
|
||||
style: dialogTheme.titleTextStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (description != null) ...[
|
||||
const SizedBox(height: AppSpacing.tiny),
|
||||
Text(
|
||||
description!,
|
||||
style: dialogTheme.contentTextStyle?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (navigation != null) ...[
|
||||
const SizedBox(height: AppSpacing.medium),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: navigation,
|
||||
),
|
||||
],
|
||||
if (!editorHeader && !contentOnly)
|
||||
const SizedBox(height: AppSpacing.compact),
|
||||
Flexible(
|
||||
fit: height == null ? FlexFit.loose : FlexFit.tight,
|
||||
child: scrollContent
|
||||
? SingleChildScrollView(child: child)
|
||||
: child,
|
||||
),
|
||||
if (actions.isNotEmpty) ...[
|
||||
const SizedBox(height: AppSpacing.compact),
|
||||
Builder(
|
||||
builder: (context) => Theme(
|
||||
data: AppTheme.dialogActionTheme(
|
||||
Theme.of(context),
|
||||
),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.end,
|
||||
spacing: AppSpacing.compact,
|
||||
runSpacing: AppSpacing.small,
|
||||
children: actions,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (editorHeader && !contentOnly) ...[
|
||||
PositionedDirectional(
|
||||
top: 0,
|
||||
start: 0,
|
||||
end: 0,
|
||||
height: editorHeaderHeight,
|
||||
child: Padding(
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
start: editorHeaderHorizontalPadding,
|
||||
end:
|
||||
editorHeaderHorizontalPadding +
|
||||
AppControlSize.headerButton +
|
||||
AppSpacing.tiny,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
if (showEditorTitle)
|
||||
Semantics(
|
||||
namesRoute: true,
|
||||
header: true,
|
||||
child: Text(
|
||||
title,
|
||||
key: const Key('app-dialog-header-title'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
if (header != null) ...[
|
||||
if (showEditorTitle)
|
||||
const SizedBox(width: AppSpacing.compact),
|
||||
Flexible(
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: KeyedSubtree(
|
||||
key: const Key('app-dialog-header-content'),
|
||||
child: header!,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
PositionedDirectional(
|
||||
top: editorHeaderHeight - 1,
|
||||
start: 0,
|
||||
end: 0,
|
||||
child: const Divider(
|
||||
key: Key('app-dialog-header-divider'),
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
PositionedDirectional(
|
||||
top: editorHeader
|
||||
? (editorHeaderHeight - AppControlSize.headerButton) / 2
|
||||
: AppSpacing.medium,
|
||||
end: editorHeader
|
||||
? editorHeaderHorizontalPadding
|
||||
: AppSpacing.medium,
|
||||
child: SizedBox.square(
|
||||
dimension: editorHeader
|
||||
? AppControlSize.headerButton
|
||||
: 24,
|
||||
child: IconButton(
|
||||
key: const Key('app-dialog-close-button'),
|
||||
tooltip:
|
||||
closeLabel ??
|
||||
MaterialLocalizations.of(context)
|
||||
.closeButtonTooltip,
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
style: IconButton.styleFrom(
|
||||
foregroundColor: colors.onSurface.withValues(
|
||||
alpha: .7,
|
||||
),
|
||||
minimumSize: Size.square(
|
||||
editorHeader ? AppControlSize.headerButton : 24,
|
||||
),
|
||||
padding: const EdgeInsets.all(AppSpacing.tiny),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppRadius.large,
|
||||
),
|
||||
),
|
||||
),
|
||||
icon: const Icon(Icons.close, size: AppIconSize.header),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// Consistent spacing between related settings fields.
|
||||
class AppFieldGroup extends StatelessWidget {
|
||||
const AppFieldGroup({super.key, required this.children});
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
spacing: AppSpacing.extraLarge,
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
|
||||
enum AppFieldOrientation { vertical, horizontal }
|
||||
|
||||
class AppField extends StatelessWidget {
|
||||
const AppField({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.child,
|
||||
this.description,
|
||||
this.error,
|
||||
this.orientation = AppFieldOrientation.vertical,
|
||||
this.enabled = true,
|
||||
});
|
||||
final String label;
|
||||
final Widget child;
|
||||
final String? description;
|
||||
final String? error;
|
||||
final AppFieldOrientation orientation;
|
||||
final bool enabled;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final heading = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: theme.textTheme.labelLarge),
|
||||
if (description != null) ...[
|
||||
const SizedBox(height: AppSpacing.hairline),
|
||||
Text(
|
||||
description!,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
return Opacity(
|
||||
opacity: enabled ? 1 : .5,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
orientation == AppFieldOrientation.horizontal &&
|
||||
constraints.maxWidth >= 440
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(child: heading),
|
||||
const SizedBox(width: AppSpacing.medium),
|
||||
Flexible(
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
heading,
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
if (error != null) ...[
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
error!,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// Compact content row with independent actions and optional selection.
|
||||
class AppItem extends StatelessWidget {
|
||||
const AppItem({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.leading,
|
||||
this.actions = const [],
|
||||
this.selected = false,
|
||||
this.onPressed,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final Widget? leading;
|
||||
final List<Widget> actions;
|
||||
final bool selected;
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final ink = theme.colorScheme.onSurface;
|
||||
final hover = AppTheme.itemHoverColor(context, selected: selected);
|
||||
return Semantics(
|
||||
container: true,
|
||||
selected: selected,
|
||||
child: Material(
|
||||
color: selected ? ink.withValues(alpha: .05) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
hoverColor: hover,
|
||||
child: SizedBox(
|
||||
height: AppControlSize.propertyItem,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
||||
child: Row(
|
||||
children: [
|
||||
if (leading != null) ...[
|
||||
leading!,
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
],
|
||||
Expanded(
|
||||
child: DefaultTextStyle(
|
||||
style: theme.textTheme.labelLarge!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
if (actions.isNotEmpty) ...[
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
...actions,
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AppItemGroup extends StatelessWidget {
|
||||
const AppItemGroup({super.key, required this.children});
|
||||
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (var i = 0; i < children.length; i++) ...[
|
||||
if (i > 0) const SizedBox(height: AppSidebarMetrics.projectGap),
|
||||
children[i],
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,670 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
import '../theme/menu_metrics.dart';
|
||||
import 'native_context_menu.dart';
|
||||
import 'app_combobox.dart';
|
||||
|
||||
part 'app_menu.freezed.dart';
|
||||
|
||||
void _focusMenu(GlobalKey entryKey) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final context = entryKey.currentContext;
|
||||
if (context == null) return;
|
||||
final scope = FocusScope.of(context);
|
||||
final policy = FocusTraversalGroup.of(context);
|
||||
policy.findFirstFocus(scope, ignoreCurrentFocus: true)?.requestFocus();
|
||||
});
|
||||
}
|
||||
|
||||
abstract final class AppMenuStyle {
|
||||
static MenuStyle panel(BuildContext context, {double minWidth = 160}) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return MenuStyle(
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
AppTheme.popoverBackground(context),
|
||||
),
|
||||
surfaceTintColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
elevation: const WidgetStatePropertyAll(4),
|
||||
shadowColor: WidgetStatePropertyAll(colors.shadow.withValues(alpha: .2)),
|
||||
minimumSize: WidgetStatePropertyAll(Size(minWidth, 0)),
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.all(AppMenuMetrics.gutter),
|
||||
),
|
||||
side: WidgetStatePropertyAll(
|
||||
BorderSide(
|
||||
color: colors.outlineVariant,
|
||||
width: AppMenuMetrics.borderWidth,
|
||||
),
|
||||
),
|
||||
shape: const WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(AppMenuMetrics.radius),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static MenuStyle selectPanel(
|
||||
BuildContext context, {
|
||||
required double minWidth,
|
||||
}) => panel(context, minWidth: minWidth);
|
||||
|
||||
static ButtonStyle selectItem(BuildContext context) => item(context);
|
||||
|
||||
static ButtonStyle descriptionItem(
|
||||
BuildContext context, {
|
||||
bool destructive = false,
|
||||
}) => item(context, destructive: destructive).copyWith(
|
||||
minimumSize: const WidgetStatePropertyAll(
|
||||
Size(0, AppMenuMetrics.descriptionRowHeight),
|
||||
),
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(
|
||||
horizontal: AppMenuMetrics.iconGap,
|
||||
vertical: AppMenuMetrics.descriptionVerticalPadding,
|
||||
),
|
||||
),
|
||||
textStyle: WidgetStatePropertyAll(
|
||||
Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontSize: AppMenuMetrics.titleFontSize,
|
||||
height: AppMenuMetrics.titleLineHeight / AppMenuMetrics.titleFontSize,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
static ButtonStyle item(BuildContext context, {bool destructive = false}) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final foreground = destructive ? colors.error : colors.onSurface;
|
||||
return ButtonStyle(
|
||||
textStyle: WidgetStatePropertyAll(
|
||||
theme.textTheme.bodyMedium?.copyWith(
|
||||
fontSize: AppMenuMetrics.fontSize,
|
||||
height: AppMenuMetrics.lineHeight / AppMenuMetrics.fontSize,
|
||||
),
|
||||
),
|
||||
iconSize: const WidgetStatePropertyAll(AppMenuMetrics.iconSize),
|
||||
minimumSize: const WidgetStatePropertyAll(
|
||||
Size(0, AppMenuMetrics.rowHeight),
|
||||
),
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: AppMenuMetrics.iconGap, vertical: 5),
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
visualDensity: VisualDensity.standard,
|
||||
shape: const WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(AppMenuMetrics.itemRadius),
|
||||
),
|
||||
),
|
||||
),
|
||||
foregroundColor: WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.disabled)
|
||||
? foreground.withValues(alpha: .5)
|
||||
: foreground,
|
||||
),
|
||||
iconColor: WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.disabled)
|
||||
? foreground.withValues(alpha: .5)
|
||||
: foreground,
|
||||
),
|
||||
backgroundColor: WidgetStateProperty.resolveWith(
|
||||
(states) =>
|
||||
states.any(
|
||||
{
|
||||
WidgetState.hovered,
|
||||
WidgetState.focused,
|
||||
WidgetState.pressed,
|
||||
}.contains,
|
||||
)
|
||||
? (destructive
|
||||
? colors.errorContainer
|
||||
: AppSidebarColors.of(context).hover)
|
||||
: Colors.transparent,
|
||||
),
|
||||
overlayColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AppMenuItem extends StatefulWidget {
|
||||
const AppMenuItem({
|
||||
super.key,
|
||||
required this.label,
|
||||
this.description,
|
||||
this.onPressed,
|
||||
this.icon,
|
||||
this.selected,
|
||||
this.destructive = false,
|
||||
this.selectOption = false,
|
||||
this.requestFocusOnHover = true,
|
||||
});
|
||||
final String label;
|
||||
final String? description;
|
||||
final VoidCallback? onPressed;
|
||||
final IconData? icon;
|
||||
final bool? selected;
|
||||
final bool destructive;
|
||||
final bool selectOption;
|
||||
final bool requestFocusOnHover;
|
||||
|
||||
@override
|
||||
State<AppMenuItem> createState() => _AppMenuItemState();
|
||||
}
|
||||
|
||||
class _AppMenuItemState extends State<AppMenuItem> {
|
||||
final _focus = FocusNode();
|
||||
bool _focusFromHover = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Semantics(
|
||||
selected: widget.selected,
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
onKeyEvent: (_, event) {
|
||||
if (event is KeyDownEvent) _focusFromHover = false;
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: MenuItemButton(
|
||||
focusNode: _focus,
|
||||
requestFocusOnHover: widget.requestFocusOnHover,
|
||||
onHover: (hovered) {
|
||||
// Material moves focus on pointer hover, but retains it on exit.
|
||||
// Release only mouse-acquired focus when scrolling moves this item
|
||||
// away; keep keyboard focus and the normal highlight transition.
|
||||
if (!hovered && _focusFromHover && _focus.hasFocus) {
|
||||
_focus.unfocus();
|
||||
}
|
||||
_focusFromHover = hovered;
|
||||
},
|
||||
onPressed: widget.onPressed,
|
||||
style: widget.description != null
|
||||
? AppMenuStyle.descriptionItem(
|
||||
context,
|
||||
destructive: widget.destructive,
|
||||
)
|
||||
: widget.selectOption
|
||||
? AppMenuStyle.selectItem(context)
|
||||
: AppMenuStyle.item(context, destructive: widget.destructive),
|
||||
leadingIcon: widget.icon == null ? null : Icon(widget.icon),
|
||||
trailingIcon: widget.selectOption || widget.selected == null
|
||||
? null
|
||||
: SizedBox.square(
|
||||
dimension: AppMenuMetrics.iconSize,
|
||||
child: widget.selected! ? const Icon(Icons.check) : null,
|
||||
),
|
||||
child: widget.selectOption
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
SizedBox.square(
|
||||
dimension: 16,
|
||||
child: widget.selected == true
|
||||
? const Icon(Icons.check, size: 16)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
)
|
||||
: widget.description == null
|
||||
? Text(widget.label, maxLines: 1, overflow: TextOverflow.ellipsis)
|
||||
: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
widget.description!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontSize: AppMenuMetrics.descriptionFontSize,
|
||||
height:
|
||||
AppMenuMetrics.descriptionLineHeight /
|
||||
AppMenuMetrics.descriptionFontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class AppMenuSeparator extends StatelessWidget {
|
||||
const AppMenuSeparator({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context) => const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: AppMenuMetrics.iconGap,
|
||||
vertical: AppMenuMetrics.separatorVerticalPadding,
|
||||
),
|
||||
child: Divider(height: 1, thickness: 1),
|
||||
);
|
||||
}
|
||||
|
||||
class AppMenuLabel extends StatelessWidget {
|
||||
const AppMenuLabel(this.label, {super.key});
|
||||
final String label;
|
||||
@override
|
||||
Widget build(BuildContext context) => Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.gap,
|
||||
vertical: AppSpacing.tiny,
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.labelMedium
|
||||
?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class AppSubmenu extends StatelessWidget {
|
||||
const AppSubmenu({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.items,
|
||||
this.icon,
|
||||
});
|
||||
final String label;
|
||||
final List<Widget> items;
|
||||
final IconData? icon;
|
||||
@override
|
||||
Widget build(BuildContext context) => SubmenuButton(
|
||||
style: AppMenuStyle.item(context),
|
||||
menuStyle: AppMenuStyle.panel(context),
|
||||
leadingIcon: icon == null ? null : Icon(icon),
|
||||
menuChildren: items,
|
||||
child: Text(label),
|
||||
);
|
||||
}
|
||||
|
||||
typedef AppMenuTriggerBuilder = Widget Function(
|
||||
BuildContext context,
|
||||
VoidCallback? toggle,
|
||||
FocusNode focusNode,
|
||||
);
|
||||
|
||||
class AppDropdownMenu extends StatefulWidget {
|
||||
const AppDropdownMenu({
|
||||
super.key,
|
||||
required this.items,
|
||||
required this.builder,
|
||||
this.enabled = true,
|
||||
this.minWidth = 160,
|
||||
this.maxHeight,
|
||||
this.onClose,
|
||||
this.menuStyle,
|
||||
this.crossAxisUnconstrained = false,
|
||||
this.alignmentOffset = const Offset(0, 4),
|
||||
});
|
||||
final List<Widget> items;
|
||||
final AppMenuTriggerBuilder builder;
|
||||
final bool enabled;
|
||||
final double minWidth;
|
||||
final double? maxHeight;
|
||||
final VoidCallback? onClose;
|
||||
final MenuStyle? menuStyle;
|
||||
final bool crossAxisUnconstrained;
|
||||
final Offset alignmentOffset;
|
||||
@override
|
||||
State<AppDropdownMenu> createState() => _AppDropdownMenuState();
|
||||
}
|
||||
|
||||
class _AppDropdownMenuState extends State<AppDropdownMenu> {
|
||||
final _focus = FocusNode();
|
||||
final _controller = MenuController();
|
||||
final _entryKey = GlobalKey();
|
||||
@override
|
||||
void dispose() {
|
||||
_focus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => MenuAnchor(
|
||||
controller: _controller,
|
||||
childFocusNode: _focus,
|
||||
consumeOutsideTap: true,
|
||||
crossAxisUnconstrained: widget.crossAxisUnconstrained,
|
||||
alignmentOffset: widget.alignmentOffset,
|
||||
style:
|
||||
(widget.menuStyle ??
|
||||
AppMenuStyle.panel(context, minWidth: widget.minWidth))
|
||||
.copyWith(
|
||||
maximumSize: widget.maxHeight == null
|
||||
? null
|
||||
: WidgetStatePropertyAll(
|
||||
Size(double.infinity, widget.maxHeight!),
|
||||
),
|
||||
),
|
||||
onClose: widget.onClose,
|
||||
onOpen: () => _focusMenu(_entryKey),
|
||||
menuChildren: [
|
||||
for (var i = 0; i < widget.items.length; i++)
|
||||
if (i == 0)
|
||||
Builder(key: _entryKey, builder: (_) => widget.items[i])
|
||||
else
|
||||
widget.items[i],
|
||||
],
|
||||
builder: (context, controller, _) => Shortcuts(
|
||||
shortcuts: const {
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown): ActivateIntent(),
|
||||
},
|
||||
child: widget.builder(
|
||||
context,
|
||||
!widget.enabled
|
||||
? null
|
||||
: () {
|
||||
controller.isOpen ? controller.close() : controller.open();
|
||||
},
|
||||
_focus,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class AppSelectOption<T> with _$AppSelectOption<T> {
|
||||
const factory AppSelectOption(
|
||||
T value,
|
||||
String label, {
|
||||
@Default(true) bool enabled,
|
||||
@Default([]) List<String> searchTerms,
|
||||
}) = _AppSelectOption<T>;
|
||||
}
|
||||
|
||||
/// Shared shadcn-style select; searchable for long option lists.
|
||||
class AppSelect<T> extends StatelessWidget {
|
||||
const AppSelect({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.options,
|
||||
required this.onChanged,
|
||||
required this.label,
|
||||
required this.emptyLabel,
|
||||
this.searchHint,
|
||||
this.outlined = true,
|
||||
this.searchable = false,
|
||||
this.controlHeight,
|
||||
this.textStyle,
|
||||
}) : assert(!searchable || searchHint != null);
|
||||
final T value;
|
||||
final List<AppSelectOption<T>> options;
|
||||
final ValueChanged<T>? onChanged;
|
||||
final String label;
|
||||
final String emptyLabel;
|
||||
final String? searchHint;
|
||||
final bool outlined;
|
||||
final bool searchable;
|
||||
final double? controlHeight;
|
||||
final TextStyle? textStyle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => searchable
|
||||
? AppCombobox<T>(
|
||||
value: value,
|
||||
options: options,
|
||||
onChanged: onChanged,
|
||||
label: label,
|
||||
emptyLabel: emptyLabel,
|
||||
searchHint: searchHint!,
|
||||
)
|
||||
: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final current = options
|
||||
.where((option) => option.value == value)
|
||||
.firstOrNull;
|
||||
final bounded = constraints.hasBoundedWidth;
|
||||
return AppDropdownMenu(
|
||||
enabled: onChanged != null,
|
||||
minWidth: outlined && bounded ? constraints.maxWidth : 160,
|
||||
maxHeight: 320,
|
||||
menuStyle: AppMenuStyle.selectPanel(
|
||||
context,
|
||||
minWidth: outlined && bounded ? constraints.maxWidth : 128,
|
||||
),
|
||||
items: [
|
||||
if (options.isEmpty) AppMenuLabel(emptyLabel),
|
||||
for (final option in options)
|
||||
AppMenuItem(
|
||||
label: option.label,
|
||||
selected: option.value == value,
|
||||
selectOption: true,
|
||||
onPressed: onChanged == null || !option.enabled
|
||||
? null
|
||||
: () => onChanged!(option.value),
|
||||
),
|
||||
],
|
||||
builder: (context, toggle, focus) => Semantics(
|
||||
label: label,
|
||||
child: Opacity(
|
||||
opacity: onChanged == null ? .5 : 1,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 100),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
boxShadow: outlined
|
||||
? [
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .05),
|
||||
offset: const Offset(0, 1),
|
||||
blurRadius: 2,
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: TextButton(
|
||||
focusNode: focus,
|
||||
onPressed: toggle,
|
||||
style: TextButton.styleFrom(
|
||||
textStyle: textStyle ?? theme.textTheme.bodyMedium,
|
||||
foregroundColor: colors.onSurface,
|
||||
disabledForegroundColor: colors.onSurface,
|
||||
overlayColor: Colors.transparent,
|
||||
backgroundColor: outlined
|
||||
? theme.inputDecorationTheme.fillColor
|
||||
: Colors.transparent,
|
||||
fixedSize: controlHeight == null
|
||||
? null
|
||||
: Size.fromHeight(controlHeight!),
|
||||
minimumSize: Size(
|
||||
0,
|
||||
outlined
|
||||
? AppControlSize.input
|
||||
: AppControlSize.small,
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
),
|
||||
side: outlined
|
||||
? theme
|
||||
.inputDecorationTheme
|
||||
.enabledBorder
|
||||
?.borderSide ??
|
||||
BorderSide(color: colors.outlineVariant)
|
||||
: null,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: outlined ? 12 : AppSpacing.tiny,
|
||||
vertical: outlined ? AppSpacing.inputVertical : 0,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(
|
||||
fit: outlined && bounded
|
||||
? FlexFit.tight
|
||||
: FlexFit.loose,
|
||||
child: Text(
|
||||
current?.label ?? label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
Icon(
|
||||
Icons.expand_more,
|
||||
size: 16,
|
||||
color: colors.onSurfaceVariant.withValues(
|
||||
alpha: .5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class AppContextMenu extends StatefulWidget {
|
||||
const AppContextMenu({
|
||||
super.key,
|
||||
required this.itemsBuilder,
|
||||
required this.child,
|
||||
});
|
||||
final List<Widget> Function(BuildContext) itemsBuilder;
|
||||
final Widget child;
|
||||
@override
|
||||
State<AppContextMenu> createState() => _AppContextMenuState();
|
||||
}
|
||||
|
||||
class _AppContextMenuState extends State<AppContextMenu> {
|
||||
final _controller = MenuController();
|
||||
final _focus = FocusNode();
|
||||
final _entryKey = GlobalKey();
|
||||
Offset _anchorPosition = Offset.zero;
|
||||
bool _focusFirstItem = false;
|
||||
bool _opening = false;
|
||||
@override
|
||||
void dispose() {
|
||||
_focus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _open(Offset position, {required bool focusFirstItem}) async {
|
||||
if (_opening) return;
|
||||
_opening = true;
|
||||
try {
|
||||
_focus.requestFocus();
|
||||
final box = context.findRenderObject() as RenderBox;
|
||||
if (await showNativeContextMenu(
|
||||
widget.itemsBuilder(context),
|
||||
box.localToGlobal(position),
|
||||
() => mounted,
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
_openFlutter(position, focusFirstItem: focusFirstItem);
|
||||
} finally {
|
||||
_opening = false;
|
||||
}
|
||||
}
|
||||
|
||||
void _openFlutter(Offset position, {required bool focusFirstItem}) {
|
||||
_focus.requestFocus();
|
||||
if (_controller.isOpen) _controller.close();
|
||||
setState(() {
|
||||
_anchorPosition = position;
|
||||
_focusFirstItem = focusFirstItem;
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) _controller.open();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Focus(
|
||||
focusNode: _focus,
|
||||
onKeyEvent: (node, event) {
|
||||
if (event is! KeyDownEvent) return KeyEventResult.ignored;
|
||||
if (event.logicalKey == LogicalKeyboardKey.contextMenu ||
|
||||
(event.logicalKey == LogicalKeyboardKey.f10 &&
|
||||
HardwareKeyboard.instance.isShiftPressed)) {
|
||||
_open(Offset.zero, focusFirstItem: true);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (_controller.isOpen &&
|
||||
!_focusFirstItem &&
|
||||
event.logicalKey == LogicalKeyboardKey.arrowDown) {
|
||||
_focusFirstItem = true;
|
||||
_focusMenu(_entryKey);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: Stack(
|
||||
fit: StackFit.passthrough,
|
||||
children: [
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
// Let Flutter finish the pointer sequence before AppKit takes over
|
||||
// event tracking, otherwise NSMenu can consume the right-button up.
|
||||
onSecondaryTapUp: (details) =>
|
||||
_open(details.localPosition, focusFirstItem: false),
|
||||
onLongPressStart: (details) =>
|
||||
_open(details.localPosition, focusFirstItem: false),
|
||||
child: widget.child,
|
||||
),
|
||||
Positioned(
|
||||
left: _anchorPosition.dx,
|
||||
top: _anchorPosition.dy,
|
||||
child: MenuAnchor(
|
||||
controller: _controller,
|
||||
childFocusNode: _focus,
|
||||
consumeOutsideTap: true,
|
||||
crossAxisUnconstrained: false,
|
||||
style: AppMenuStyle.panel(context),
|
||||
onOpen: () {
|
||||
if (_focusFirstItem) _focusMenu(_entryKey);
|
||||
},
|
||||
menuChildren: _items(context),
|
||||
child: const IgnorePointer(child: SizedBox.square(dimension: 1)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
List<Widget> _items(BuildContext context) {
|
||||
final items = widget.itemsBuilder(context);
|
||||
return [
|
||||
for (var i = 0; i < items.length; i++)
|
||||
if (i == 0)
|
||||
Builder(key: _entryKey, builder: (_) => items[i])
|
||||
else
|
||||
items[i],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint, type=warning, deprecated_member_use, deprecated_member_use_from_same_package
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'app_menu.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$AppSelectOption<T> {
|
||||
|
||||
T get value; String get label; bool get enabled; List<String> get searchTerms;
|
||||
/// Create a copy of AppSelectOption
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$AppSelectOptionCopyWith<T, AppSelectOption<T>> get copyWith => _$AppSelectOptionCopyWithImpl<T, AppSelectOption<T>>(this as AppSelectOption<T>, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as AppSelectOption<T>;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is AppSelectOption<T>&&const DeepCollectionEquality().equals(other.value, _this.value)&&(identical(other.label, _this.label) || other.label == _this.label)&&(identical(other.enabled, _this.enabled) || other.enabled == _this.enabled)&&const DeepCollectionEquality().equals(other.searchTerms, _this.searchTerms));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as AppSelectOption<T>;
|
||||
return Object.hash(runtimeType,const DeepCollectionEquality().hash(_this.value),_this.label,_this.enabled,const DeepCollectionEquality().hash(_this.searchTerms));
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as AppSelectOption<T>;
|
||||
return 'AppSelectOption<$T>(value: ${_this.value}, label: ${_this.label}, enabled: ${_this.enabled}, searchTerms: ${_this.searchTerms})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $AppSelectOptionCopyWith<T,$Res> {
|
||||
factory $AppSelectOptionCopyWith(AppSelectOption<T> value, $Res Function(AppSelectOption<T>) _then) = _$AppSelectOptionCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
T value, String label, bool enabled, List<String> searchTerms
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$AppSelectOptionCopyWithImpl<T,$Res>
|
||||
implements $AppSelectOptionCopyWith<T, $Res> {
|
||||
_$AppSelectOptionCopyWithImpl(this._self, this._then);
|
||||
|
||||
final AppSelectOption<T> _self;
|
||||
final $Res Function(AppSelectOption<T>) _then;
|
||||
|
||||
/// Create a copy of AppSelectOption
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? value = freezed,Object? label = null,Object? enabled = null,Object? searchTerms = null,}) {
|
||||
return _then(AppSelectOption(
|
||||
freezed == value ? _self.value : value // ignore: cast_nullable_to_non_nullable
|
||||
as T,null == label ? _self.label : label // ignore: cast_nullable_to_non_nullable
|
||||
as String,enabled: null == enabled ? _self.enabled : enabled // ignore: cast_nullable_to_non_nullable
|
||||
as bool,searchTerms: null == searchTerms ? _self.searchTerms : searchTerms // ignore: cast_nullable_to_non_nullable
|
||||
as List<String>,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [AppSelectOption].
|
||||
extension AppSelectOptionPatterns<T> on AppSelectOption<T> {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _AppSelectOption<T> value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSelectOption() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _AppSelectOption<T> value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSelectOption():
|
||||
return $default(_that);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _AppSelectOption<T> value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSelectOption() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( T value, String label, bool enabled, List<String> searchTerms)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSelectOption() when $default != null:
|
||||
return $default(_that.value,_that.label,_that.enabled,_that.searchTerms);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( T value, String label, bool enabled, List<String> searchTerms) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSelectOption():
|
||||
return $default(_that.value,_that.label,_that.enabled,_that.searchTerms);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( T value, String label, bool enabled, List<String> searchTerms)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSelectOption() when $default != null:
|
||||
return $default(_that.value,_that.label,_that.enabled,_that.searchTerms);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _AppSelectOption<T> implements AppSelectOption<T> {
|
||||
const _AppSelectOption(this.value, this.label, {this.enabled = true, List<String> searchTerms = const []}): _searchTerms = searchTerms;
|
||||
|
||||
|
||||
@override final T value;
|
||||
@override final String label;
|
||||
@override@JsonKey() final bool enabled;
|
||||
final List<String> _searchTerms;
|
||||
@override@JsonKey() List<String> get searchTerms {
|
||||
if (_searchTerms is EqualUnmodifiableListView) return _searchTerms;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_searchTerms);
|
||||
}
|
||||
|
||||
|
||||
/// Create a copy of AppSelectOption
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$AppSelectOptionCopyWith<T, _AppSelectOption<T>> get copyWith => __$AppSelectOptionCopyWithImpl<T, _AppSelectOption<T>>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppSelectOption<T>&&const DeepCollectionEquality().equals(other.value, value)&&(identical(other.label, label) || other.label == label)&&(identical(other.enabled, enabled) || other.enabled == enabled)&&const DeepCollectionEquality().equals(other.searchTerms, _searchTerms));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,const DeepCollectionEquality().hash(value),label,enabled,const DeepCollectionEquality().hash(_searchTerms));
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AppSelectOption<$T>(value: $value, label: $label, enabled: $enabled, searchTerms: $searchTerms)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$AppSelectOptionCopyWith<T,$Res> implements $AppSelectOptionCopyWith<T, $Res> {
|
||||
factory _$AppSelectOptionCopyWith(_AppSelectOption<T> value, $Res Function(_AppSelectOption<T>) _then) = __$AppSelectOptionCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
T value, String label, bool enabled, List<String> searchTerms
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$AppSelectOptionCopyWithImpl<T,$Res>
|
||||
implements _$AppSelectOptionCopyWith<T, $Res> {
|
||||
__$AppSelectOptionCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _AppSelectOption<T> _self;
|
||||
final $Res Function(_AppSelectOption<T>) _then;
|
||||
|
||||
/// Create a copy of AppSelectOption
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? value = freezed,Object? label = null,Object? enabled = null,Object? searchTerms = null,}) {
|
||||
return _then(_AppSelectOption<T>(
|
||||
freezed == value ? _self.value : value // ignore: cast_nullable_to_non_nullable
|
||||
as T,null == label ? _self.label : label // ignore: cast_nullable_to_non_nullable
|
||||
as String,enabled: null == enabled ? _self.enabled : enabled // ignore: cast_nullable_to_non_nullable
|
||||
as bool,searchTerms: null == searchTerms ? _self._searchTerms : searchTerms // ignore: cast_nullable_to_non_nullable
|
||||
as List<String>,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,154 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
import '../theme/menu_metrics.dart';
|
||||
|
||||
/// Anchored shadcn-style surface, dismissed outside or with Escape.
|
||||
class AppPopover extends StatefulWidget {
|
||||
const AppPopover({
|
||||
super.key,
|
||||
required this.builder,
|
||||
required this.child,
|
||||
this.width = 288,
|
||||
this.maxHeight = 480,
|
||||
this.enabled = true,
|
||||
this.alignment = AlignmentDirectional.bottomStart,
|
||||
this.surfaceKey,
|
||||
this.backgroundColor,
|
||||
this.borderRadius = AppMenuMetrics.radius,
|
||||
this.padding = const EdgeInsets.all(AppMenuMetrics.gutter),
|
||||
});
|
||||
|
||||
final Widget Function(BuildContext, VoidCallback toggle) builder;
|
||||
final Widget child;
|
||||
final double width;
|
||||
final double maxHeight;
|
||||
final bool enabled;
|
||||
final AlignmentGeometry alignment;
|
||||
final Key? surfaceKey;
|
||||
final Color? backgroundColor;
|
||||
final double borderRadius;
|
||||
final EdgeInsetsGeometry padding;
|
||||
|
||||
@override
|
||||
State<AppPopover> createState() => _AppPopoverState();
|
||||
}
|
||||
|
||||
class _AppPopoverState extends State<AppPopover> {
|
||||
final _menu = MenuController();
|
||||
|
||||
void _toggle() {
|
||||
if (!widget.enabled) return;
|
||||
if (_menu.isOpen) {
|
||||
_menu.close();
|
||||
} else {
|
||||
_menu.open();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(AppPopover oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!widget.enabled && _menu.isOpen) _menu.close();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final viewport = MediaQuery.sizeOf(context);
|
||||
final surfaceWidth = math.min(
|
||||
widget.width,
|
||||
math.max(0.0, viewport.width - 32),
|
||||
);
|
||||
final endAligned = widget.alignment == AlignmentDirectional.bottomEnd;
|
||||
final direction = Directionality.of(context);
|
||||
return MenuAnchor(
|
||||
controller: _menu,
|
||||
alignmentOffset: Offset(
|
||||
endAligned
|
||||
? (direction == TextDirection.ltr ? -surfaceWidth : surfaceWidth)
|
||||
: 0,
|
||||
4,
|
||||
),
|
||||
consumeOutsideTap: false,
|
||||
crossAxisUnconstrained: false,
|
||||
clipBehavior: Clip.none,
|
||||
style: MenuStyle(
|
||||
alignment: widget.alignment,
|
||||
padding: const WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
backgroundColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
surfaceTintColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
shadowColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
// The inner surface owns the border; do not inherit MenuTheme's stroke.
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
),
|
||||
),
|
||||
menuChildren: [
|
||||
SizedBox(
|
||||
key: widget.surfaceKey,
|
||||
width: surfaceWidth,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
widget.backgroundColor ?? AppTheme.popoverBackground(context),
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
border: Border.all(
|
||||
color: colors.outlineVariant,
|
||||
width: AppMenuMetrics.borderWidth,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .1),
|
||||
offset: const Offset(0, 4),
|
||||
blurRadius: 6,
|
||||
spreadRadius: -1,
|
||||
),
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .1),
|
||||
offset: const Offset(0, 2),
|
||||
blurRadius: 4,
|
||||
spreadRadius: -2,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
child: Padding(
|
||||
padding: widget.padding,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: math.max(
|
||||
0,
|
||||
math.min(widget.maxHeight, viewport.height - 96),
|
||||
),
|
||||
),
|
||||
child: Focus(
|
||||
autofocus: true,
|
||||
onKeyEvent: (_, event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
_menu.close();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
builder: (context, _, _) => widget.builder(context, _toggle),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// A numeric field's drag handle; the owner controls values and history.
|
||||
class AppScrubLabel extends StatefulWidget {
|
||||
const AppScrubLabel({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.enabled,
|
||||
required this.onStart,
|
||||
required this.onUpdate,
|
||||
required this.onEnd,
|
||||
required this.onCancel,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final bool enabled;
|
||||
final bool Function() onStart;
|
||||
final ValueChanged<double> onUpdate;
|
||||
final VoidCallback onEnd;
|
||||
final VoidCallback onCancel;
|
||||
|
||||
@override
|
||||
State<AppScrubLabel> createState() => _AppScrubLabelState();
|
||||
}
|
||||
|
||||
class _AppScrubLabelState extends State<AppScrubLabel> {
|
||||
final _focus = FocusNode(skipTraversal: true);
|
||||
bool _active = false;
|
||||
Offset? _down;
|
||||
|
||||
void _update(Offset position) {
|
||||
final down = _down;
|
||||
if (!_active || down == null) return;
|
||||
widget.onUpdate(position.dx - down.dx);
|
||||
}
|
||||
|
||||
void _cancel() {
|
||||
_down = null;
|
||||
if (!_active) return;
|
||||
_active = false;
|
||||
widget.onCancel();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant AppScrubLabel oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!widget.enabled && _active) {
|
||||
_active = false;
|
||||
_down = null;
|
||||
scheduleMicrotask(widget.onCancel);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (_active) scheduleMicrotask(widget.onCancel);
|
||||
_focus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Focus(
|
||||
focusNode: _focus,
|
||||
onFocusChange: (focused) {
|
||||
if (!focused) _cancel();
|
||||
},
|
||||
onKeyEvent: (_, event) {
|
||||
if (_active &&
|
||||
event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
_cancel();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: MouseRegion(
|
||||
cursor: widget.enabled
|
||||
? SystemMouseCursors.resizeLeftRight
|
||||
: SystemMouseCursors.basic,
|
||||
child: Listener(
|
||||
onPointerCancel: (_) => _cancel(),
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onHorizontalDragDown: (details) => _down = details.globalPosition,
|
||||
onHorizontalDragStart: (details) {
|
||||
if (!widget.enabled || !widget.onStart()) return;
|
||||
_active = true;
|
||||
_focus.requestFocus();
|
||||
_update(details.globalPosition);
|
||||
},
|
||||
onHorizontalDragUpdate: (event) {
|
||||
_update(event.globalPosition);
|
||||
},
|
||||
onHorizontalDragEnd: (_) {
|
||||
if (!_active) return;
|
||||
_active = false;
|
||||
_down = null;
|
||||
widget.onEnd();
|
||||
},
|
||||
onHorizontalDragCancel: _cancel,
|
||||
child: Align(
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
||||
child: Text(
|
||||
widget.label,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
class AppSlider extends StatelessWidget {
|
||||
const AppSlider({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.min = 0,
|
||||
this.max = 1,
|
||||
this.divisions,
|
||||
this.label,
|
||||
this.focusNode,
|
||||
this.semanticFormatterCallback,
|
||||
this.onChangeStart,
|
||||
this.onChangeEnd,
|
||||
});
|
||||
|
||||
final double value;
|
||||
final double min;
|
||||
final double max;
|
||||
final int? divisions;
|
||||
final String? label;
|
||||
final FocusNode? focusNode;
|
||||
final SemanticFormatterCallback? semanticFormatterCallback;
|
||||
final ValueChanged<double>? onChanged;
|
||||
final ValueChanged<double>? onChangeStart;
|
||||
final ValueChanged<double>? onChangeEnd;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final accent = colors.primary;
|
||||
return SizedBox(
|
||||
height: AppControlSize.standard,
|
||||
child: SliderTheme(
|
||||
data: SliderTheme.of(context).copyWith(
|
||||
trackHeight: 4,
|
||||
trackGap: 0,
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.compact),
|
||||
activeTrackColor: accent,
|
||||
inactiveTrackColor: colors.secondaryContainer,
|
||||
disabledActiveTrackColor: colors.onSurface.withValues(alpha: 0.24),
|
||||
disabledInactiveTrackColor: colors.outlineVariant,
|
||||
thumbColor: colors.onPrimary,
|
||||
disabledThumbColor: colors.onSurface.withValues(alpha: 0.38),
|
||||
overlayColor: accent.withValues(alpha: 0.14),
|
||||
thumbShape: const RoundSliderThumbShape(
|
||||
enabledThumbRadius: 6,
|
||||
disabledThumbRadius: 6,
|
||||
elevation: 1,
|
||||
pressedElevation: 1,
|
||||
),
|
||||
overlayShape: const RoundSliderOverlayShape(overlayRadius: 12),
|
||||
trackShape: const RoundedRectSliderTrackShape(),
|
||||
showValueIndicator: ShowValueIndicator.never,
|
||||
),
|
||||
child: Slider(
|
||||
value: value,
|
||||
min: min,
|
||||
max: max,
|
||||
divisions: divisions,
|
||||
label: label,
|
||||
focusNode: focusNode,
|
||||
semanticFormatterCallback: semanticFormatterCallback,
|
||||
onChanged: onChanged,
|
||||
onChangeStart: onChangeStart,
|
||||
onChangeEnd: onChangeEnd,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// Keeps Flutter switch semantics and keyboard handling under a Nova visual.
|
||||
class AppSwitch extends StatefulWidget {
|
||||
const AppSwitch({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.semanticLabel,
|
||||
this.focusNode,
|
||||
this.small = false,
|
||||
});
|
||||
final bool value;
|
||||
final ValueChanged<bool>? onChanged;
|
||||
final String? semanticLabel;
|
||||
final FocusNode? focusNode;
|
||||
final bool small;
|
||||
@override
|
||||
State<AppSwitch> createState() => _AppSwitchState();
|
||||
}
|
||||
|
||||
class _AppSwitchState extends State<AppSwitch> {
|
||||
bool _focused = false;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final width = widget.small ? 24.0 : 32.0;
|
||||
final height = widget.small ? 14.0 : 20.0;
|
||||
final states = <WidgetState>{
|
||||
if (widget.value) WidgetState.selected,
|
||||
if (widget.onChanged == null) WidgetState.disabled,
|
||||
};
|
||||
final thumb = widget.small ? 12.0 : 16.0;
|
||||
return Semantics(
|
||||
label: widget.semanticLabel,
|
||||
child: Focus(
|
||||
onFocusChange: (value) => setState(() => _focused = value),
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
height: 36,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Opacity(
|
||||
opacity: widget.onChanged == null ? .5 : 1,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 100),
|
||||
width: width,
|
||||
height: height,
|
||||
padding: const EdgeInsets.all(1),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(AppRadius.pill),
|
||||
color: AppTheme.switchTrackColor(context, states),
|
||||
boxShadow: _focused
|
||||
? [
|
||||
BoxShadow(
|
||||
color: colors.outline.withValues(alpha: .5),
|
||||
spreadRadius: 3,
|
||||
),
|
||||
]
|
||||
: [],
|
||||
),
|
||||
child: AnimatedAlign(
|
||||
duration: const Duration(milliseconds: 100),
|
||||
alignment: widget.value
|
||||
? AlignmentDirectional.centerEnd
|
||||
: AlignmentDirectional.centerStart,
|
||||
child: SizedBox.square(
|
||||
dimension: thumb,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppTheme.switchThumbColor(context, states),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned.fill(
|
||||
child: Opacity(
|
||||
opacity: 0,
|
||||
alwaysIncludeSemantics: true,
|
||||
child: Switch(
|
||||
value: widget.value,
|
||||
onChanged: widget.onChanged,
|
||||
focusNode: widget.focusNode,
|
||||
padding: EdgeInsets.zero,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
part 'app_tabs.freezed.dart';
|
||||
|
||||
@freezed
|
||||
abstract class AppTab<T> with _$AppTab<T> {
|
||||
const factory AppTab(
|
||||
T value,
|
||||
String label, {
|
||||
IconData? icon,
|
||||
@Default(true) bool enabled,
|
||||
}) = _AppTab<T>;
|
||||
}
|
||||
|
||||
class AppTabs<T> extends StatefulWidget {
|
||||
const AppTabs({
|
||||
super.key,
|
||||
required this.tabs,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.textStyle,
|
||||
this.iconSize = 16,
|
||||
this.headerStyle = false,
|
||||
});
|
||||
final List<AppTab<T>> tabs;
|
||||
final T value;
|
||||
final ValueChanged<T> onChanged;
|
||||
final TextStyle? textStyle;
|
||||
final double iconSize;
|
||||
final bool headerStyle;
|
||||
@override
|
||||
State<AppTabs<T>> createState() => _AppTabsState<T>();
|
||||
}
|
||||
|
||||
class _AppTabsState<T> extends State<AppTabs<T>> {
|
||||
final _focus = <T, FocusNode>{};
|
||||
@override
|
||||
void dispose() {
|
||||
for (final node in _focus.values) {
|
||||
node.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant AppTabs<T> oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
for (final value in _focus.keys.toList()) {
|
||||
if (!widget.tabs.any((tab) => tab.value == value)) {
|
||||
_focus.remove(value)!.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _navigate(T value, LogicalKeyboardKey key) {
|
||||
final tabs = widget.tabs.where((tab) => tab.enabled).toList();
|
||||
if (tabs.isEmpty) return;
|
||||
final index = tabs.indexWhere((tab) => tab.value == value);
|
||||
final rtl = Directionality.of(context) == TextDirection.rtl;
|
||||
final step = (key == LogicalKeyboardKey.arrowRight) != rtl ? 1 : -1;
|
||||
final next = key == LogicalKeyboardKey.home
|
||||
? 0
|
||||
: key == LogicalKeyboardKey.end
|
||||
? tabs.length - 1
|
||||
: (index + step) % tabs.length;
|
||||
_focus[tabs[next].value]?.requestFocus();
|
||||
widget.onChanged(tabs[next].value);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Container(
|
||||
height: widget.headerStyle ? 38 : 32,
|
||||
padding: const EdgeInsets.all(AppSpacing.inputVertical),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.secondaryContainer,
|
||||
borderRadius: BorderRadius.circular(widget.headerStyle ? 10 : 8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final tab in widget.tabs)
|
||||
Focus(
|
||||
onKeyEvent: (_, event) {
|
||||
if (event is KeyDownEvent &&
|
||||
[
|
||||
LogicalKeyboardKey.arrowLeft,
|
||||
LogicalKeyboardKey.arrowRight,
|
||||
LogicalKeyboardKey.home,
|
||||
LogicalKeyboardKey.end,
|
||||
].contains(event.logicalKey)) {
|
||||
_navigate(tab.value, event.logicalKey);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: Semantics(
|
||||
selected: widget.value == tab.value,
|
||||
child: TextButton(
|
||||
focusNode: _focus.putIfAbsent(tab.value, FocusNode.new),
|
||||
onPressed: tab.enabled
|
||||
? () {
|
||||
_focus[tab.value]?.requestFocus();
|
||||
widget.onChanged(tab.value);
|
||||
}
|
||||
: null,
|
||||
style: TextButton.styleFrom(
|
||||
textStyle: widget.textStyle,
|
||||
minimumSize: Size(0, widget.headerStyle ? 32 : 26),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: widget.headerStyle ? 10 : 6,
|
||||
),
|
||||
foregroundColor: widget.value == tab.value
|
||||
? colors.onSurface
|
||||
: colors.onSurfaceVariant,
|
||||
backgroundColor: widget.value == tab.value
|
||||
? colors.surface
|
||||
: Colors.transparent,
|
||||
side: BorderSide(
|
||||
color: AppTheme.tabBorderColor(
|
||||
context,
|
||||
selected: widget.value == tab.value,
|
||||
headerStyle: widget.headerStyle,
|
||||
),
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
widget.headerStyle ? 8 : 6,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (tab.icon != null) ...[
|
||||
Icon(tab.icon, size: widget.iconSize),
|
||||
SizedBox(width: widget.headerStyle ? 8 : 6),
|
||||
],
|
||||
Text(tab.label),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint, type=warning, deprecated_member_use, deprecated_member_use_from_same_package
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'app_tabs.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$AppTab<T> {
|
||||
|
||||
T get value; String get label; IconData? get icon; bool get enabled;
|
||||
/// Create a copy of AppTab
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$AppTabCopyWith<T, AppTab<T>> get copyWith => _$AppTabCopyWithImpl<T, AppTab<T>>(this as AppTab<T>, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as AppTab<T>;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is AppTab<T>&&const DeepCollectionEquality().equals(other.value, _this.value)&&(identical(other.label, _this.label) || other.label == _this.label)&&(identical(other.icon, _this.icon) || other.icon == _this.icon)&&(identical(other.enabled, _this.enabled) || other.enabled == _this.enabled));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as AppTab<T>;
|
||||
return Object.hash(runtimeType,const DeepCollectionEquality().hash(_this.value),_this.label,_this.icon,_this.enabled);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as AppTab<T>;
|
||||
return 'AppTab<$T>(value: ${_this.value}, label: ${_this.label}, icon: ${_this.icon}, enabled: ${_this.enabled})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $AppTabCopyWith<T,$Res> {
|
||||
factory $AppTabCopyWith(AppTab<T> value, $Res Function(AppTab<T>) _then) = _$AppTabCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
T value, String label, IconData? icon, bool enabled
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$AppTabCopyWithImpl<T,$Res>
|
||||
implements $AppTabCopyWith<T, $Res> {
|
||||
_$AppTabCopyWithImpl(this._self, this._then);
|
||||
|
||||
final AppTab<T> _self;
|
||||
final $Res Function(AppTab<T>) _then;
|
||||
|
||||
/// Create a copy of AppTab
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? value = freezed,Object? label = null,Object? icon = freezed,Object? enabled = null,}) {
|
||||
return _then(AppTab(
|
||||
freezed == value ? _self.value : value // ignore: cast_nullable_to_non_nullable
|
||||
as T,null == label ? _self.label : label // ignore: cast_nullable_to_non_nullable
|
||||
as String,icon: freezed == icon ? _self.icon : icon // ignore: cast_nullable_to_non_nullable
|
||||
as IconData?,enabled: null == enabled ? _self.enabled : enabled // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [AppTab].
|
||||
extension AppTabPatterns<T> on AppTab<T> {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _AppTab<T> value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AppTab() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _AppTab<T> value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AppTab():
|
||||
return $default(_that);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _AppTab<T> value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AppTab() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( T value, String label, IconData? icon, bool enabled)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppTab() when $default != null:
|
||||
return $default(_that.value,_that.label,_that.icon,_that.enabled);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( T value, String label, IconData? icon, bool enabled) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppTab():
|
||||
return $default(_that.value,_that.label,_that.icon,_that.enabled);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( T value, String label, IconData? icon, bool enabled)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppTab() when $default != null:
|
||||
return $default(_that.value,_that.label,_that.icon,_that.enabled);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _AppTab<T> implements AppTab<T> {
|
||||
const _AppTab(this.value, this.label, {this.icon, this.enabled = true});
|
||||
|
||||
|
||||
@override final T value;
|
||||
@override final String label;
|
||||
@override final IconData? icon;
|
||||
@override@JsonKey() final bool enabled;
|
||||
|
||||
/// Create a copy of AppTab
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$AppTabCopyWith<T, _AppTab<T>> get copyWith => __$AppTabCopyWithImpl<T, _AppTab<T>>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppTab<T>&&const DeepCollectionEquality().equals(other.value, value)&&(identical(other.label, label) || other.label == label)&&(identical(other.icon, icon) || other.icon == icon)&&(identical(other.enabled, enabled) || other.enabled == enabled));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,const DeepCollectionEquality().hash(value),label,icon,enabled);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AppTab<$T>(value: $value, label: $label, icon: $icon, enabled: $enabled)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$AppTabCopyWith<T,$Res> implements $AppTabCopyWith<T, $Res> {
|
||||
factory _$AppTabCopyWith(_AppTab<T> value, $Res Function(_AppTab<T>) _then) = __$AppTabCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
T value, String label, IconData? icon, bool enabled
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$AppTabCopyWithImpl<T,$Res>
|
||||
implements _$AppTabCopyWith<T, $Res> {
|
||||
__$AppTabCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _AppTab<T> _self;
|
||||
final $Res Function(_AppTab<T>) _then;
|
||||
|
||||
/// Create a copy of AppTab
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? value = freezed,Object? label = null,Object? icon = freezed,Object? enabled = null,}) {
|
||||
return _then(_AppTab<T>(
|
||||
freezed == value ? _self.value : value // ignore: cast_nullable_to_non_nullable
|
||||
as T,null == label ? _self.label : label // ignore: cast_nullable_to_non_nullable
|
||||
as String,icon: freezed == icon ? _self.icon : icon // ignore: cast_nullable_to_non_nullable
|
||||
as IconData?,enabled: null == enabled ? _self.enabled : enabled // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,198 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// Shared inline-labelled input built on Flutter's native text editing.
|
||||
class AppTextField extends StatefulWidget {
|
||||
const AppTextField({
|
||||
super.key,
|
||||
this.controller,
|
||||
this.focusNode,
|
||||
this.label,
|
||||
this.leading,
|
||||
this.unit,
|
||||
this.hintText,
|
||||
this.errorText,
|
||||
this.enabled = true,
|
||||
this.readOnly = false,
|
||||
this.canRequestFocus = true,
|
||||
this.keyboardType,
|
||||
this.inputFormatters,
|
||||
this.minLines,
|
||||
this.maxLines = 1,
|
||||
this.textInputAction,
|
||||
this.onChanged,
|
||||
this.onEditingComplete,
|
||||
this.onSubmitted,
|
||||
this.onTapOutside,
|
||||
});
|
||||
|
||||
final TextEditingController? controller;
|
||||
final FocusNode? focusNode;
|
||||
final String? label;
|
||||
final Widget? leading;
|
||||
final String? unit;
|
||||
final String? hintText;
|
||||
final String? errorText;
|
||||
final bool enabled;
|
||||
|
||||
final bool readOnly;
|
||||
final bool canRequestFocus;
|
||||
final TextInputType? keyboardType;
|
||||
final List<TextInputFormatter>? inputFormatters;
|
||||
final int? minLines;
|
||||
final int? maxLines;
|
||||
final TextInputAction? textInputAction;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final VoidCallback? onEditingComplete;
|
||||
final ValueChanged<String>? onSubmitted;
|
||||
final TapRegionCallback? onTapOutside;
|
||||
|
||||
@override
|
||||
State<AppTextField> createState() => _AppTextFieldState();
|
||||
}
|
||||
|
||||
class _AppTextFieldState extends State<AppTextField> {
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final foreground = widget.enabled
|
||||
? colors.onSurface
|
||||
: colors.onSurface.withValues(alpha: 0.38);
|
||||
final focusColor = colors.primary;
|
||||
final borderless =
|
||||
theme.inputDecorationTheme.enabledBorder?.borderSide == BorderSide.none;
|
||||
final style = theme.textTheme.bodyMedium!.copyWith(
|
||||
color: foreground,
|
||||
letterSpacing: 0,
|
||||
);
|
||||
OutlineInputBorder border(Color color) => OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
borderSide: BorderSide(color: color),
|
||||
);
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: Semantics(
|
||||
label: [widget.label, widget.unit].whereType<String>().join(' '),
|
||||
child: TextField(
|
||||
controller: widget.controller,
|
||||
focusNode: widget.focusNode,
|
||||
enabled: widget.enabled,
|
||||
readOnly: widget.readOnly,
|
||||
canRequestFocus: widget.canRequestFocus,
|
||||
keyboardType: widget.keyboardType,
|
||||
inputFormatters: widget.inputFormatters,
|
||||
minLines: widget.minLines,
|
||||
maxLines: widget.maxLines,
|
||||
textInputAction: widget.textInputAction,
|
||||
style: style,
|
||||
cursorColor: focusColor,
|
||||
cursorHeight: AppTheme.inputCursorHeight(context),
|
||||
cursorWidth: 1,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: theme.inputDecorationTheme.fillColor,
|
||||
hoverColor: Colors.transparent,
|
||||
hintText: widget.hintText,
|
||||
hintStyle:
|
||||
theme.inputDecorationTheme.hintStyle ??
|
||||
style.copyWith(color: colors.onSurfaceVariant),
|
||||
errorText: widget.errorText,
|
||||
errorMaxLines: 2,
|
||||
contentPadding:
|
||||
theme.inputDecorationTheme.contentPadding ??
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.controlHorizontal,
|
||||
vertical: AppSpacing.inputVertical,
|
||||
),
|
||||
prefixIcon:
|
||||
widget.leading ??
|
||||
(widget.label == null
|
||||
? null
|
||||
: Align(
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.small,
|
||||
),
|
||||
child: ExcludeSemantics(
|
||||
child: Text(
|
||||
widget.label!,
|
||||
style: style.copyWith(
|
||||
color: widget.enabled
|
||||
? colors.onSurfaceVariant
|
||||
: foreground,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
prefixIconConstraints: const BoxConstraints(
|
||||
minWidth: AppControlSize.standard,
|
||||
minHeight: AppControlSize.input,
|
||||
),
|
||||
suffixIcon: widget.unit == null
|
||||
? null
|
||||
: Align(
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.small,
|
||||
),
|
||||
child: ExcludeSemantics(
|
||||
child: Text(
|
||||
widget.unit!,
|
||||
style: style.copyWith(
|
||||
color: widget.enabled
|
||||
? colors.onSurfaceVariant
|
||||
: foreground,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
suffixIconConstraints: const BoxConstraints(
|
||||
minWidth: AppControlSize.compact,
|
||||
minHeight: AppControlSize.input,
|
||||
),
|
||||
border: theme.inputDecorationTheme.border,
|
||||
enabledBorder: borderless
|
||||
? theme.inputDecorationTheme.enabledBorder
|
||||
: border(
|
||||
_hovered
|
||||
? colors.outline
|
||||
: theme
|
||||
.inputDecorationTheme
|
||||
.enabledBorder
|
||||
?.borderSide
|
||||
.color ??
|
||||
colors.outlineVariant,
|
||||
),
|
||||
disabledBorder: theme.inputDecorationTheme.disabledBorder,
|
||||
focusedBorder: theme.inputDecorationTheme.focusedBorder,
|
||||
errorBorder: borderless
|
||||
? theme.inputDecorationTheme.errorBorder
|
||||
: border(colors.error),
|
||||
focusedErrorBorder: borderless
|
||||
? theme.inputDecorationTheme.focusedErrorBorder
|
||||
: border(colors.error),
|
||||
),
|
||||
onChanged: widget.onChanged,
|
||||
onEditingComplete: widget.onEditingComplete,
|
||||
onSubmitted: widget.onSubmitted,
|
||||
onTapOutside: widget.onTapOutside,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
class CompactPanelTabs<T> extends StatelessWidget {
|
||||
const CompactPanelTabs({
|
||||
super.key,
|
||||
required this.values,
|
||||
required this.selected,
|
||||
required this.labelBuilder,
|
||||
required this.onSelected,
|
||||
this.tabKeyBuilder,
|
||||
this.padding = const EdgeInsets.all(AppSpacing.gap),
|
||||
});
|
||||
|
||||
static const height = AppControlSize.panelToolbar;
|
||||
|
||||
final List<T> values;
|
||||
final T selected;
|
||||
final String Function(T) labelBuilder;
|
||||
final ValueChanged<T> onSelected;
|
||||
final Key Function(T)? tabKeyBuilder;
|
||||
final EdgeInsetsGeometry padding;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SizedBox(
|
||||
height: height,
|
||||
child: Padding(
|
||||
padding: padding,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (final value in values)
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
end: value == values.last ? 0 : AppSpacing.tiny,
|
||||
),
|
||||
child: Semantics(
|
||||
selected: selected == value,
|
||||
child: TextButton(
|
||||
key: tabKeyBuilder?.call(value),
|
||||
onPressed: () => onSelected(value),
|
||||
style: AppTheme.panelTabStyle(
|
||||
context,
|
||||
selected: selected == value,
|
||||
),
|
||||
child: Text(
|
||||
labelBuilder(value),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Keeps brief operations from flashing a loading indicator.
|
||||
class DelayedLoadingIndicator extends StatefulWidget {
|
||||
const DelayedLoadingIndicator({super.key, required this.child});
|
||||
|
||||
static const delay = Duration(milliseconds: 200);
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<DelayedLoadingIndicator> createState() =>
|
||||
_DelayedLoadingIndicatorState();
|
||||
}
|
||||
|
||||
class _DelayedLoadingIndicatorState extends State<DelayedLoadingIndicator> {
|
||||
Timer? _timer;
|
||||
bool _visible = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_timer = Timer(DelayedLoadingIndicator.delay, () {
|
||||
if (mounted) setState(() => _visible = true);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
_visible ? widget.child : const SizedBox.shrink();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cutdex_native/cutdex_native.dart';
|
||||
|
||||
import 'app_menu.dart';
|
||||
|
||||
/// Returns false when native menus are unavailable or an entry is unsupported.
|
||||
Future<bool> showNativeContextMenu(
|
||||
List<Widget> items,
|
||||
Offset position,
|
||||
bool Function() isMounted,
|
||||
) async {
|
||||
if (kIsWeb || defaultTargetPlatform != TargetPlatform.macOS) return false;
|
||||
final actions = <VoidCallback?>[];
|
||||
List<NativeMenuEntry>? encode(List<Widget> entries) {
|
||||
final encoded = <NativeMenuEntry>[];
|
||||
for (final entry in entries) {
|
||||
switch (entry) {
|
||||
case AppMenuItem():
|
||||
final id = actions.length;
|
||||
actions.add(entry.onPressed);
|
||||
encoded.add(
|
||||
NativeMenuEntry(
|
||||
id: id,
|
||||
label: entry.label,
|
||||
enabled: entry.onPressed != null,
|
||||
selected: entry.selected == true,
|
||||
),
|
||||
);
|
||||
case AppMenuSeparator():
|
||||
encoded.add(const NativeMenuEntry.separator());
|
||||
case AppMenuLabel():
|
||||
encoded.add(NativeMenuEntry(label: entry.label, enabled: false));
|
||||
case AppSubmenu():
|
||||
final children = encode(entry.items);
|
||||
if (children == null) return null;
|
||||
encoded.add(NativeMenuEntry(label: entry.label, children: children));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
final entries = encode(items);
|
||||
if (entries == null) return false;
|
||||
try {
|
||||
final selected = await NativeContextMenu.show(entries, position);
|
||||
if (isMounted() &&
|
||||
selected != null &&
|
||||
selected >= 0 &&
|
||||
selected < actions.length) {
|
||||
actions[selected]?.call();
|
||||
}
|
||||
return true;
|
||||
} on NativeMenuUnavailableException {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
/// Byte-based download progress shared by resource dialogs and task details.
|
||||
class ResourceDownloadProgress extends StatelessWidget {
|
||||
const ResourceDownloadProgress({
|
||||
super.key,
|
||||
required this.downloadedBytes,
|
||||
required this.totalBytes,
|
||||
required this.status,
|
||||
this.paused = false,
|
||||
this.bytesPerSecond = 0,
|
||||
});
|
||||
|
||||
final int downloadedBytes;
|
||||
final int totalBytes;
|
||||
final String status;
|
||||
final bool paused;
|
||||
final int bytesPerSecond;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final total = totalBytes;
|
||||
final downloaded = downloadedBytes.clamp(0, total);
|
||||
final progress = total <= 0 ? 0.0 : downloaded / total;
|
||||
final speedPrefix = paused
|
||||
? ''
|
||||
: '${formatResourceBytes(bytesPerSecond)}/s - ';
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'$speedPrefix'
|
||||
'${formatResourceBytes(downloaded)}/${formatResourceBytes(total)}'
|
||||
'${status.isEmpty ? '' : ', $status'}',
|
||||
style: AppTheme.resourceProgressTextStyle(context),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.tiny),
|
||||
LinearProgressIndicator(
|
||||
value: progress,
|
||||
minHeight: 3,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(2)),
|
||||
color: theme.colorScheme.primary,
|
||||
backgroundColor: theme.dividerColor,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String formatResourceBytes(int bytes) {
|
||||
if (bytes < 1000) return '$bytes B';
|
||||
final units = ['KB', 'MB', 'GB', 'TB'];
|
||||
var amount = bytes.toDouble();
|
||||
var unit = -1;
|
||||
do {
|
||||
amount /= 1000;
|
||||
unit++;
|
||||
} while (amount >= 1000 && unit < units.length - 1);
|
||||
final precision = amount >= 100 ? 0 : 1;
|
||||
return '${amount.toStringAsFixed(precision)} ${units[unit]}';
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Owns the controller shared by a scroll view and its edge fade.
|
||||
class ScrollEdgeFadeBuilder extends StatefulWidget {
|
||||
const ScrollEdgeFadeBuilder({
|
||||
super.key,
|
||||
required this.builder,
|
||||
this.axis = Axis.vertical,
|
||||
this.fadeExtent = 24,
|
||||
});
|
||||
|
||||
final Widget Function(ScrollController controller) builder;
|
||||
final Axis axis;
|
||||
final double fadeExtent;
|
||||
|
||||
@override
|
||||
State<ScrollEdgeFadeBuilder> createState() => _ScrollEdgeFadeBuilderState();
|
||||
}
|
||||
|
||||
class _ScrollEdgeFadeBuilderState extends State<ScrollEdgeFadeBuilder> {
|
||||
final ScrollController _controller = ScrollController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ScrollEdgeFade(
|
||||
controller: _controller,
|
||||
axis: widget.axis,
|
||||
fadeExtent: widget.fadeExtent,
|
||||
child: widget.builder(_controller),
|
||||
);
|
||||
}
|
||||
|
||||
/// Fades overflowing scroll content at the viewport edges.
|
||||
///
|
||||
/// [controller] must also be attached to the child scroll view and remains
|
||||
/// owned by the caller. [axis] must match the child scroll view's axis.
|
||||
class ScrollEdgeFade extends StatefulWidget {
|
||||
const ScrollEdgeFade({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.child,
|
||||
this.axis = Axis.vertical,
|
||||
this.fadeExtent = 24,
|
||||
this.bottomInset = 0,
|
||||
}) : assert(fadeExtent > 0 && fadeExtent < double.infinity);
|
||||
|
||||
final ScrollController controller;
|
||||
final Widget child;
|
||||
final Axis axis;
|
||||
final double fadeExtent;
|
||||
|
||||
/// Keeps the bottom fade above an overlay while the scroll view fills it.
|
||||
final double bottomInset;
|
||||
|
||||
@override
|
||||
State<ScrollEdgeFade> createState() => _ScrollEdgeFadeState();
|
||||
}
|
||||
|
||||
class _ScrollEdgeFadeState extends State<ScrollEdgeFade> {
|
||||
double _fadeStart = 0;
|
||||
double _fadeEnd = 0;
|
||||
bool _updateScheduled = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.controller.addListener(_updateFade);
|
||||
_scheduleFadeUpdate();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ScrollEdgeFade oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.controller != widget.controller) {
|
||||
oldWidget.controller.removeListener(_updateFade);
|
||||
widget.controller.addListener(_updateFade);
|
||||
}
|
||||
_scheduleFadeUpdate();
|
||||
}
|
||||
|
||||
void _scheduleFadeUpdate() {
|
||||
if (_updateScheduled) return;
|
||||
_updateScheduled = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_updateScheduled = false;
|
||||
if (mounted) _updateFade();
|
||||
});
|
||||
}
|
||||
|
||||
void _updateFade() {
|
||||
final controller = widget.controller;
|
||||
if (!controller.hasClients || !controller.position.hasContentDimensions) {
|
||||
return;
|
||||
}
|
||||
final position = controller.position;
|
||||
final reversed =
|
||||
position.axisDirection == AxisDirection.up ||
|
||||
position.axisDirection == AxisDirection.left;
|
||||
final before = (position.extentBefore / widget.fadeExtent).clamp(0.0, 1.0);
|
||||
final after = (position.extentAfter / widget.fadeExtent).clamp(0.0, 1.0);
|
||||
final start = reversed ? after : before;
|
||||
final end = reversed ? before : after;
|
||||
if ((start - _fadeStart).abs() > 0.005 || (end - _fadeEnd).abs() > 0.005) {
|
||||
setState(() {
|
||||
_fadeStart = start;
|
||||
_fadeEnd = end;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller.removeListener(_updateFade);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
NotificationListener<ScrollMetricsNotification>(
|
||||
onNotification: (notification) {
|
||||
if (notification.depth == 0) _scheduleFadeUpdate();
|
||||
return false;
|
||||
},
|
||||
child: ShaderMask(
|
||||
blendMode: BlendMode.dstIn,
|
||||
shaderCallback: (bounds) {
|
||||
final vertical = widget.axis == Axis.vertical;
|
||||
final extent = vertical ? bounds.height : bounds.width;
|
||||
final fadeSize = extent <= widget.fadeExtent * 2
|
||||
? 0.5
|
||||
: widget.fadeExtent / extent;
|
||||
final inset = vertical ? widget.bottomInset : 0.0;
|
||||
final visibleEnd = extent <= 0
|
||||
? 0.0
|
||||
: ((extent - inset) / extent).clamp(0.0, 1.0);
|
||||
final insetFadeSize = fadeSize.clamp(0.0, visibleEnd / 2);
|
||||
return LinearGradient(
|
||||
begin: vertical ? Alignment.topCenter : Alignment.centerLeft,
|
||||
end: vertical ? Alignment.bottomCenter : Alignment.centerRight,
|
||||
stops: inset <= 0
|
||||
? [0, fadeSize, 1 - fadeSize, 1]
|
||||
: [
|
||||
0,
|
||||
insetFadeSize,
|
||||
visibleEnd - insetFadeSize,
|
||||
visibleEnd,
|
||||
visibleEnd,
|
||||
1,
|
||||
],
|
||||
colors: inset <= 0
|
||||
? [
|
||||
Colors.white.withValues(alpha: 1 - _fadeStart),
|
||||
Colors.white,
|
||||
Colors.white,
|
||||
Colors.white.withValues(alpha: 1 - _fadeEnd),
|
||||
]
|
||||
: [
|
||||
Colors.white.withValues(alpha: 1 - _fadeStart),
|
||||
Colors.white,
|
||||
Colors.white,
|
||||
Colors.white.withValues(alpha: 1 - _fadeEnd),
|
||||
Colors.transparent,
|
||||
Colors.transparent,
|
||||
],
|
||||
).createShader(bounds);
|
||||
},
|
||||
child: widget.child,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
class WorkspacePanel extends StatelessWidget {
|
||||
const WorkspacePanel({
|
||||
super.key,
|
||||
this.title,
|
||||
this.icon,
|
||||
required this.child,
|
||||
this.trailing,
|
||||
this.controls,
|
||||
this.headerHeight = AppControlSize.panelHeader,
|
||||
this.headerPadding = const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.compact,
|
||||
),
|
||||
this.showHeaderDivider = true,
|
||||
this.paintBackground = true,
|
||||
});
|
||||
|
||||
final String? title;
|
||||
final IconData? icon;
|
||||
final Widget child;
|
||||
final Widget? trailing;
|
||||
final Widget? controls;
|
||||
final double headerHeight;
|
||||
final EdgeInsetsGeometry headerPadding;
|
||||
final bool showHeaderDivider;
|
||||
final bool paintBackground;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final content = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: headerHeight,
|
||||
child: Padding(
|
||||
padding: headerPadding,
|
||||
child: Row(
|
||||
children: [
|
||||
if (icon case final icon?) ...[
|
||||
Icon(icon, size: AppIconSize.small),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
],
|
||||
if (title case final title?)
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
),
|
||||
if (controls case final controls?) ...[
|
||||
if (title != null) const SizedBox(width: AppSpacing.small),
|
||||
Expanded(child: controls),
|
||||
],
|
||||
if (trailing case final trailing?) ...[
|
||||
if (title == null && controls == null) const Spacer(),
|
||||
trailing,
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showHeaderDivider) const Divider(),
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
if (!paintBackground) return content;
|
||||
return ColoredBox(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: content,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export 'src/theme/app_theme.dart';
|
||||
export 'src/theme/menu_metrics.dart';
|
||||
@@ -0,0 +1,18 @@
|
||||
export 'src/widgets/app_button_group.dart';
|
||||
export 'src/widgets/app_combobox.dart';
|
||||
export 'src/widgets/app_dialog.dart';
|
||||
export 'src/widgets/app_field.dart';
|
||||
export 'src/widgets/app_item.dart';
|
||||
export 'src/widgets/app_menu.dart';
|
||||
export 'src/widgets/app_popover.dart';
|
||||
export 'src/widgets/app_scrub_label.dart';
|
||||
export 'src/widgets/app_slider.dart';
|
||||
export 'src/widgets/app_switch.dart';
|
||||
export 'src/widgets/app_tabs.dart';
|
||||
export 'src/widgets/app_text_field.dart';
|
||||
export 'src/widgets/compact_panel_tabs.dart';
|
||||
export 'src/widgets/delayed_loading_indicator.dart';
|
||||
export 'src/widgets/native_context_menu.dart';
|
||||
export 'src/widgets/scroll_edge_fade.dart';
|
||||
export 'src/widgets/workspace_panel.dart';
|
||||
export 'src/widgets/resource_download_progress.dart';
|
||||
@@ -0,0 +1,18 @@
|
||||
name: cutdex_ui
|
||||
description: Shared Cutdex widgets and visual theme.
|
||||
version: 0.1.0
|
||||
publish_to: none
|
||||
resolution: workspace
|
||||
environment:
|
||||
sdk: ^3.13.2
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
cutdex_native: ^0.1.0
|
||||
freezed_annotation: ^3.1.0
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^6.0.0
|
||||
build_runner: ^2.16.1
|
||||
freezed: ^4.0.2
|
||||
@@ -0,0 +1,129 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('standard dialog uses Codex spacing, type and button size', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () => showAppDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => AppDialog(
|
||||
title: '下载资源',
|
||||
description: '下载所需模型',
|
||||
actions: [
|
||||
TextButton(onPressed: () {}, child: const Text('取消')),
|
||||
FilledButton(onPressed: () {}, child: const Text('下载')),
|
||||
],
|
||||
child: const Text('正在准备资源'),
|
||||
),
|
||||
),
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final frame = tester.getRect(find.byKey(const Key('app-dialog-frame')));
|
||||
final title = tester.getRect(find.text('下载资源'));
|
||||
final description = tester.getRect(find.text('下载所需模型'));
|
||||
final body = tester.getRect(find.text('正在准备资源'));
|
||||
final close = tester.getRect(
|
||||
find.byKey(const Key('app-dialog-close-button')),
|
||||
);
|
||||
final action = tester.getRect(find.widgetWithText(FilledButton, '下载'));
|
||||
final cancel = tester.getRect(find.widgetWithText(TextButton, '取消'));
|
||||
expect(title.left - frame.left, AppSpacing.large);
|
||||
expect(frame.width, 420);
|
||||
expect(title.top - frame.top, AppSpacing.large);
|
||||
expect(body.left - frame.left, AppSpacing.large);
|
||||
expect(description.top - title.bottom, AppSpacing.tiny);
|
||||
expect(body.top - description.bottom, AppSpacing.compact);
|
||||
expect(frame.right - close.right, AppSpacing.medium);
|
||||
expect(close.top - frame.top, AppSpacing.medium);
|
||||
expect(close.size, const Size.square(24));
|
||||
expect(
|
||||
Theme.of(tester.element(find.text('下载')))
|
||||
.filledButtonTheme
|
||||
.style!
|
||||
.minimumSize!
|
||||
.resolve({}),
|
||||
const Size(0, 32),
|
||||
);
|
||||
expect(action.height, 32);
|
||||
expect(cancel.height, 32);
|
||||
expect(action.left - cancel.right, AppSpacing.compact);
|
||||
expect(frame.right - action.right, AppSpacing.large);
|
||||
expect(action.top - body.bottom, AppSpacing.compact);
|
||||
expect(frame.bottom - action.bottom, AppSpacing.large);
|
||||
expect(tester.widget<Text>(find.text('下载资源')).style?.fontSize, 20);
|
||||
expect(
|
||||
tester.widget<Text>(find.text('下载资源')).style?.fontWeight,
|
||||
FontWeight.w600,
|
||||
);
|
||||
expect(
|
||||
DefaultTextStyle.of(tester.element(find.text('正在准备资源'))).style.fontSize,
|
||||
14,
|
||||
);
|
||||
expect(
|
||||
Theme.of(tester.element(find.text('正在准备资源'))).dialogTheme.backgroundColor,
|
||||
const Color(0xFF242424),
|
||||
);
|
||||
final shape = AppTheme.penDark.dialogTheme.shape! as RoundedRectangleBorder;
|
||||
expect(shape.borderRadius, BorderRadius.circular(AppRadius.dialog));
|
||||
expect(shape.side, BorderSide.none);
|
||||
expect(
|
||||
Theme.of(tester.element(find.text('取消')))
|
||||
.textButtonTheme
|
||||
.style!
|
||||
.textStyle!
|
||||
.resolve({})!
|
||||
.fontSize,
|
||||
14,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('selection dialog returns the chosen option', (tester) async {
|
||||
String? selected;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () async {
|
||||
selected = await showAppDialog<String>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AppDialog(
|
||||
title: '选择目标片段',
|
||||
child: AppDialogOption(
|
||||
label: '片段 A',
|
||||
onPressed: () => Navigator.pop(dialogContext, 'a'),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('app-dialog-frame')), findsOneWidget);
|
||||
await tester.tap(find.text('片段 A'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, 'a');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('property list rows use the project item gap without a line', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Theme(
|
||||
data: AppTheme.propertiesPanelTheme(AppTheme.penDark),
|
||||
child: Scaffold(
|
||||
body: AppItemGroup(
|
||||
children: [
|
||||
AppItem(
|
||||
key: const Key('first-mask'),
|
||||
leading: IconButton(
|
||||
key: const Key('mask-visibility'),
|
||||
icon: const Icon(Icons.visibility_outlined),
|
||||
onPressed: () {},
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
key: const Key('mask-delete'),
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
child: const Text('蒙版 1'),
|
||||
),
|
||||
const AppItem(key: Key('second-mask'), child: Text('蒙版 2')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('first-mask'))).height,
|
||||
AppControlSize.propertyItem,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('second-mask'))).height,
|
||||
AppControlSize.propertyItem,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('mask-visibility'))).height,
|
||||
AppControlSize.propertyControl,
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('second-mask'))).top -
|
||||
tester.getRect(find.byKey(const Key('first-mask'))).bottom,
|
||||
AppSidebarMetrics.projectGap,
|
||||
);
|
||||
expect(find.byType(Divider), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('property list hover and selection use translucent ink', (
|
||||
tester,
|
||||
) async {
|
||||
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
|
||||
Future<void> mount({required bool selected}) => tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Theme(
|
||||
data: AppTheme.propertiesPanelTheme(theme),
|
||||
child: Scaffold(
|
||||
body: AppItem(
|
||||
selected: selected,
|
||||
onPressed: () {},
|
||||
child: const Text('蒙版 1'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Finder row<T extends Widget>() =>
|
||||
find.descendant(of: find.byType(AppItem), matching: find.byType(T));
|
||||
final ink = theme.colorScheme.onSurface;
|
||||
await mount(selected: false);
|
||||
expect(
|
||||
tester.widget<Material>(row<Material>()).color,
|
||||
Colors.transparent,
|
||||
);
|
||||
expect(
|
||||
tester.widget<InkWell>(row<InkWell>()).hoverColor,
|
||||
ink.withValues(
|
||||
alpha: theme.brightness == Brightness.dark ? .078 : .058,
|
||||
),
|
||||
);
|
||||
|
||||
await mount(selected: true);
|
||||
expect(
|
||||
tester.widget<Material>(row<Material>()).color,
|
||||
ink.withValues(alpha: .05),
|
||||
);
|
||||
expect(
|
||||
tester.widget<InkWell>(row<InkWell>()).hoverColor,
|
||||
ink.withValues(alpha: .05),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'native menu waits for right-button release and dismissal keeps left clicks working',
|
||||
(tester) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
const channel = MethodChannel('cutdex_native/context_menu');
|
||||
var opened = 0;
|
||||
var clicked = 0;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
_,
|
||||
) async {
|
||||
opened++;
|
||||
return null;
|
||||
});
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penLight,
|
||||
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
AppContextMenu(
|
||||
itemsBuilder: (_) => [
|
||||
AppMenuItem(label: 'Action', onPressed: () {}),
|
||||
],
|
||||
child: const SizedBox(width: 200, height: 200),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => clicked++,
|
||||
child: const Text('Other control'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
for (var i = 0; i < 2; i++) {
|
||||
final pointer = await tester.startGesture(
|
||||
tester.getCenter(find.byType(AppContextMenu)),
|
||||
kind: PointerDeviceKind.mouse,
|
||||
buttons: kSecondaryMouseButton,
|
||||
);
|
||||
// Hold past the tap-down deadline: native tracking must not start yet.
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(opened, i);
|
||||
await pointer.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, i + 1);
|
||||
expect(find.text('Action'), findsNothing);
|
||||
await tester.tap(find.text('Other control'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(clicked, i + 1);
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'searchable shared select filters languages and resets after selection',
|
||||
(tester) async {
|
||||
var value = 'ja';
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penLight,
|
||||
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 280,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) => AppSelect<String>(
|
||||
emptyLabel: '没有匹配的选项',
|
||||
label: '源语言',
|
||||
value: value,
|
||||
searchable: true,
|
||||
searchHint: '搜索选项',
|
||||
onChanged: (next) => setState(() => value = next),
|
||||
options: const [
|
||||
AppSelectOption('ja', '日语 (ja)'),
|
||||
AppSelectOption('zh', '中文 (zh)'),
|
||||
AppSelectOption('en', '英语 (en)', enabled: false),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byType(TextField));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextField), 'zh');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.widgetWithText(MenuItemButton, '日语 (ja)'), findsNothing);
|
||||
await tester.tap(find.widgetWithText(MenuItemButton, '中文 (zh)'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(value, 'zh');
|
||||
await tester.tap(find.byType(TextField));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.widgetWithText(MenuItemButton, '日语 (ja)'), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<MenuItemButton>(
|
||||
find.widgetWithText(MenuItemButton, '英语 (en)'),
|
||||
)
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(MenuItemButton), findsNothing);
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField)).controller!.text,
|
||||
'中文 (zh)',
|
||||
);
|
||||
await tester.tap(find.byType(TextField));
|
||||
await tester.enterText(find.byType(TextField), 'unknown');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('没有匹配的选项'), findsOneWidget);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(value, 'zh');
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField)).controller!.text,
|
||||
'中文 (zh)',
|
||||
);
|
||||
await tester.tap(find.byType(TextField));
|
||||
await tester.enterText(find.byType(TextField), 'ja');
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
expect(value, 'ja');
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField)).controller!.text,
|
||||
'日语 (ja)',
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'stationary mouse scroll releases old hover focus without shifting the menu',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 280,
|
||||
child: AppSelect<int>(
|
||||
emptyLabel: 'No matching options',
|
||||
label: 'Language',
|
||||
value: 0,
|
||||
searchable: true,
|
||||
searchHint: '搜索选项',
|
||||
onChanged: (_) {},
|
||||
options: [
|
||||
for (var i = 0; i < 40; i++)
|
||||
AppSelectOption(i, 'Language $i'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byType(TextField));
|
||||
await tester.pumpAndSettle();
|
||||
final previous = find.widgetWithText(MenuItemButton, 'Language 3');
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: Offset.zero);
|
||||
await mouse.moveTo(tester.getCenter(previous));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<MenuItemButton>(previous).focusNode!.hasFocus,
|
||||
isFalse,
|
||||
);
|
||||
final scrollable = tester
|
||||
.stateList<ScrollableState>(find.byType(Scrollable))
|
||||
.firstWhere((state) => state.axisDirection == AxisDirection.down);
|
||||
scrollable.position.jumpTo(24);
|
||||
// Do not move the pointer: allow the normal transition to finish.
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<MenuItemButton>(previous).focusNode!.hasFocus,
|
||||
isFalse,
|
||||
);
|
||||
expect(scrollable.position.pixels, 24);
|
||||
final highlight = const Color(0xFFFCFCFC).withValues(alpha: 0.078);
|
||||
final backgrounds = tester.widgetList<Material>(
|
||||
find.descendant(
|
||||
of: find.byType(MenuItemButton),
|
||||
matching: find.byType(Material),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
backgrounds.where((material) => material.color == highlight),
|
||||
hasLength(1),
|
||||
);
|
||||
await mouse.removePointer();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('select works inside a dialog in both themes', (tester) async {
|
||||
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
|
||||
var value = 1;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) => Scaffold(
|
||||
body: AlertDialog(
|
||||
content: SizedBox(
|
||||
width: 360,
|
||||
child: AppSelect<int>(
|
||||
emptyLabel: 'No matching options',
|
||||
value: value,
|
||||
label: 'Theme',
|
||||
options: const [
|
||||
AppSelectOption(1, 'System'),
|
||||
AppSelectOption(2, 'Dark'),
|
||||
AppSelectOption(3, 'Disabled', enabled: false),
|
||||
],
|
||||
onChanged: (next) => setState(() => value = next),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byType(TextButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byIcon(Icons.check), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.widgetWithText(MenuItemButton, 'Dark')).height,
|
||||
28,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<MenuItemButton>(
|
||||
find.widgetWithText(MenuItemButton, 'Disabled'),
|
||||
)
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
await tester.tap(find.widgetWithText(MenuItemButton, 'Dark'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(value, 2);
|
||||
expect(find.byType(MenuItemButton), findsNothing);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('dropdown supports keyboard selection and escape', (
|
||||
tester,
|
||||
) async {
|
||||
var selected = false;
|
||||
late FocusNode triggerFocus;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penLight,
|
||||
home: Scaffold(
|
||||
body: AppDropdownMenu(
|
||||
items: [
|
||||
AppMenuItem(label: 'Action', onPressed: () => selected = true),
|
||||
],
|
||||
builder: (context, toggle, focus) {
|
||||
triggerFocus = focus;
|
||||
return TextButton(
|
||||
focusNode: focus,
|
||||
onPressed: toggle,
|
||||
child: const Text('Open'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
triggerFocus.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Action'), findsOneWidget);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, isTrue);
|
||||
expect(triggerFocus.hasFocus, isTrue);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Action'), findsNothing);
|
||||
expect(triggerFocus.hasFocus, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('context menu clamps at edges and opens submenu', (tester) async {
|
||||
var selected = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: AppContextMenu(
|
||||
itemsBuilder: (_) => [
|
||||
AppSubmenu(
|
||||
label: 'More',
|
||||
items: [
|
||||
AppMenuItem(
|
||||
label: 'Action',
|
||||
onPressed: () => selected = true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tapAt(const Offset(795, 595), buttons: kSecondaryMouseButton);
|
||||
await tester.pumpAndSettle();
|
||||
final rect = tester.getRect(find.byType(SubmenuButton));
|
||||
expect(rect.right, lessThanOrEqualTo(800));
|
||||
expect(rect.bottom, lessThanOrEqualTo(600));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Action'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, isTrue);
|
||||
expect(find.text('More'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'context menu stays beside a bottom pointer in an offset region',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(left: 180, top: 120),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 460,
|
||||
child: AppContextMenu(
|
||||
itemsBuilder: (_) => const [
|
||||
AppMenuItem(label: 'Action 1'),
|
||||
AppMenuItem(label: 'Action 2'),
|
||||
AppMenuItem(label: 'Action 3'),
|
||||
AppMenuItem(label: 'Action 4'),
|
||||
AppMenuItem(label: 'Action 5'),
|
||||
],
|
||||
child: const ColoredBox(color: Colors.black),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
const pointer = Offset(340, 560);
|
||||
await tester.tapAt(pointer, buttons: kSecondaryMouseButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final items = find.byType(MenuItemButton);
|
||||
expect(items, findsNWidgets(5));
|
||||
final first = tester.getRect(items.first);
|
||||
final last = tester.getRect(items.last);
|
||||
expect(first.left, closeTo(pointer.dx + 6, 1));
|
||||
expect(first.top, greaterThan(380));
|
||||
expect(last.bottom, lessThanOrEqualTo(pointer.dy));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'context menu only focuses its first item when opened by keyboard',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: AppContextMenu(
|
||||
itemsBuilder: (_) => const [AppMenuItem(label: 'Action')],
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tapAt(
|
||||
const Offset(300, 300),
|
||||
buttons: kSecondaryMouseButton,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Action'), findsOneWidget);
|
||||
expect(FocusManager.instance.primaryFocus, isA<FocusNode>());
|
||||
expect(FocusManager.instance.primaryFocus, isNot(isA<FocusScopeNode>()));
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.contextMenu);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Action'), findsOneWidget);
|
||||
expect(FocusManager.instance.primaryFocus, isA<FocusScopeNode>());
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'popover anchors below its trigger and dismisses outside and with Escape',
|
||||
(tester) async {
|
||||
var outsideClicks = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penLight,
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppPopover(
|
||||
builder: (_, toggle) => IconButton(
|
||||
key: const Key('trigger'),
|
||||
onPressed: toggle,
|
||||
icon: const Icon(Icons.task_alt),
|
||||
),
|
||||
child: const Text('Tasks'),
|
||||
),
|
||||
const SizedBox(height: 200),
|
||||
TextButton(
|
||||
onPressed: () => outsideClicks++,
|
||||
child: const Text('Outside'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('trigger')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Tasks'), findsOneWidget);
|
||||
// The menu host must not add a second outline around the inner surface.
|
||||
final menuSurface = tester
|
||||
.widgetList<Material>(
|
||||
find.ancestor(
|
||||
of: find.text('Tasks'),
|
||||
matching: find.byType(Material),
|
||||
),
|
||||
)
|
||||
.firstWhere((material) => material.shape is OutlinedBorder);
|
||||
expect(
|
||||
(menuSurface.shape! as OutlinedBorder).side.style,
|
||||
BorderStyle.none,
|
||||
);
|
||||
|
||||
expect(
|
||||
tester.getTopLeft(find.text('Tasks')).dy,
|
||||
greaterThan(tester.getBottomLeft(find.byKey(const Key('trigger'))).dy),
|
||||
);
|
||||
await tester.tap(find.text('Outside'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Tasks'), findsNothing);
|
||||
expect(outsideClicks, 1);
|
||||
await tester.tap(find.byKey(const Key('trigger')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Tasks'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('end-aligned popover stays inside the viewport', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penLight,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: AppPopover(
|
||||
width: 288,
|
||||
alignment: AlignmentDirectional.bottomEnd,
|
||||
surfaceKey: const Key('surface'),
|
||||
builder: (_, toggle) => TextButton(
|
||||
key: const Key('trigger'),
|
||||
onPressed: toggle,
|
||||
child: const Text('Open'),
|
||||
),
|
||||
child: const Text('Content'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('trigger')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('surface'))).left,
|
||||
greaterThanOrEqualTo(0),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'dialog fits small screens and restores trigger focus on escape',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(320, 400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final focus = FocusNode();
|
||||
addTearDown(focus.dispose);
|
||||
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => TextButton(
|
||||
focusNode: focus,
|
||||
onPressed: () => showAppDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => AppDialog(
|
||||
title: 'Settings',
|
||||
width: 1040,
|
||||
height: 680,
|
||||
actions: [
|
||||
TextButton(onPressed: () {}, child: const Text('Save')),
|
||||
],
|
||||
child: Column(
|
||||
children: List.generate(
|
||||
12,
|
||||
(index) => AppField(
|
||||
label: 'Field $index',
|
||||
error: index == 0 ? 'Invalid' : null,
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
child: const TextField(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
focus.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Settings'), findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(find.byType(Dialog)).right,
|
||||
lessThanOrEqualTo(320),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Settings'), findsNothing);
|
||||
expect(focus.hasFocus, isTrue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('tabs navigate enabled options and switch supports keyboard', (
|
||||
tester,
|
||||
) async {
|
||||
var tab = 0;
|
||||
var enabled = false;
|
||||
final focus = FocusNode();
|
||||
addTearDown(focus.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, update) => Column(
|
||||
children: [
|
||||
AppTabs<int>(
|
||||
tabs: const [
|
||||
AppTab(0, 'General'),
|
||||
AppTab(1, 'Disabled', enabled: false),
|
||||
AppTab(2, 'MCP'),
|
||||
],
|
||||
value: tab,
|
||||
onChanged: (value) => update(() => tab = value),
|
||||
),
|
||||
AppSwitch(
|
||||
value: enabled,
|
||||
focusNode: focus,
|
||||
semanticLabel: 'Service',
|
||||
onChanged: (value) => update(() => enabled = value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('General'));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
expect(tab, 2);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.home);
|
||||
await tester.pump();
|
||||
expect(tab, 0);
|
||||
focus.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.space);
|
||||
await tester.pumpAndSettle();
|
||||
expect(enabled, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('Icon button states use translucent ink without stacking selection', () {
|
||||
final style = AppTheme.penDark.iconButtonTheme.style!;
|
||||
const ink = Color(0xFFFCFCFC);
|
||||
expect(style.foregroundColor!.resolve({}), ink.withValues(alpha: .498));
|
||||
expect(style.backgroundColor!.resolve({}), Colors.transparent);
|
||||
expect(
|
||||
style.overlayColor!.resolve({WidgetState.hovered}),
|
||||
ink.withValues(alpha: .078),
|
||||
);
|
||||
expect(
|
||||
style.overlayColor!.resolve({WidgetState.pressed}),
|
||||
ink.withValues(alpha: .078),
|
||||
);
|
||||
expect(
|
||||
style.backgroundColor!.resolve({WidgetState.selected}),
|
||||
ink.withValues(alpha: .05),
|
||||
);
|
||||
expect(style.foregroundColor!.resolve({WidgetState.selected}), ink);
|
||||
expect(
|
||||
style.foregroundColor!.resolve({WidgetState.hovered}),
|
||||
ink.withValues(alpha: .498),
|
||||
);
|
||||
expect(
|
||||
style.backgroundColor!.resolve({
|
||||
WidgetState.selected,
|
||||
WidgetState.hovered,
|
||||
}),
|
||||
ink.withValues(alpha: .10),
|
||||
);
|
||||
expect(
|
||||
style.overlayColor!.resolve({WidgetState.selected, WidgetState.hovered}),
|
||||
Colors.transparent,
|
||||
);
|
||||
expect(
|
||||
style.overlayColor!.resolve({WidgetState.disabled, WidgetState.hovered}),
|
||||
Colors.transparent,
|
||||
);
|
||||
});
|
||||
|
||||
test('Scrollbar uses neutral translucent states and a transparent track', () {
|
||||
final theme = AppTheme.penDark.scrollbarTheme;
|
||||
const ink = Color(0xFFFCFCFC);
|
||||
expect(theme.thumbColor!.resolve({}), ink.withValues(alpha: .084));
|
||||
expect(
|
||||
theme.thumbColor!.resolve({WidgetState.hovered}),
|
||||
ink.withValues(alpha: .156),
|
||||
);
|
||||
expect(
|
||||
theme.thumbColor!.resolve({WidgetState.dragged}),
|
||||
ink.withValues(alpha: .156),
|
||||
);
|
||||
expect(
|
||||
theme.trackColor!.resolve({WidgetState.hovered}),
|
||||
Colors.transparent,
|
||||
);
|
||||
expect(
|
||||
theme.trackBorderColor!.resolve({WidgetState.hovered}),
|
||||
Colors.transparent,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('property inputs use the composer surface and text colors', (
|
||||
tester,
|
||||
) async {
|
||||
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
|
||||
final inspector = AppTheme.propertiesPanelTheme(theme);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Theme(
|
||||
data: inspector,
|
||||
child: const Scaffold(
|
||||
body: AppTextField(label: 'X', hintText: 'Value'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final input = tester.widget<TextField>(find.byType(TextField));
|
||||
final decoration = input.decoration!;
|
||||
expect(
|
||||
decoration.fillColor,
|
||||
theme.extension<AppSurfaces>()!.composerBackground,
|
||||
);
|
||||
expect(input.style!.color, theme.colorScheme.onSurface);
|
||||
expect(input.cursorHeight, input.style!.fontSize);
|
||||
expect(
|
||||
decoration.hintStyle!.color,
|
||||
inspector.inputDecorationTheme.hintStyle!.color,
|
||||
);
|
||||
for (final border in [
|
||||
decoration.border,
|
||||
decoration.enabledBorder,
|
||||
decoration.disabledBorder,
|
||||
decoration.focusedBorder,
|
||||
decoration.errorBorder,
|
||||
decoration.focusedErrorBorder,
|
||||
]) {
|
||||
expect(border, isA<OutlineInputBorder>());
|
||||
expect(border!.borderSide, BorderSide.none);
|
||||
expect(
|
||||
(border as OutlineInputBorder).borderRadius,
|
||||
BorderRadius.circular(AppRadius.large),
|
||||
);
|
||||
}
|
||||
await tester.tap(find.byType(TextField));
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('property input fill paints the full 28px control height', (
|
||||
tester,
|
||||
) async {
|
||||
const boundaryKey = ValueKey('property-input-pixels');
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Theme(
|
||||
data: AppTheme.propertiesPanelTheme(AppTheme.penDark),
|
||||
child: const Scaffold(
|
||||
body: Center(
|
||||
child: RepaintBoundary(
|
||||
key: boundaryKey,
|
||||
child: SizedBox(
|
||||
width: 120,
|
||||
height: AppControlSize.propertyControl,
|
||||
child: AppTextField(label: 'X'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getSize(find.byType(TextField)).height,
|
||||
AppControlSize.propertyControl,
|
||||
);
|
||||
final boundary = tester.renderObject<RenderRepaintBoundary>(
|
||||
find.byKey(boundaryKey),
|
||||
);
|
||||
await tester.runAsync(() async {
|
||||
final image = await boundary.toImage(pixelRatio: 1);
|
||||
final pixels = (await image.toByteData(
|
||||
format: ui.ImageByteFormat.rawRgba,
|
||||
))!;
|
||||
List<int> pixel(int x, int y) {
|
||||
final offset = (y * image.width + x) * 4;
|
||||
return List.generate(4, (channel) => pixels.getUint8(offset + channel));
|
||||
}
|
||||
|
||||
expect(pixel(60, 14), [47, 47, 47, 255]);
|
||||
expect(pixel(60, 0), pixel(60, 14));
|
||||
expect(pixel(60, 27), pixel(60, 14));
|
||||
image.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('system typography and themed controls work in light and dark', (
|
||||
tester,
|
||||
) async {
|
||||
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
|
||||
var enabled = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 280,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const AppTextField(label: 'W', unit: '%'),
|
||||
AppSwitch(
|
||||
value: enabled,
|
||||
onChanged: (value) => setState(() => enabled = value),
|
||||
),
|
||||
AppSlider(value: .5, onChanged: (_) {}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField)).style!.fontFamily,
|
||||
AppTheme.systemFontFamily(
|
||||
Theme.of(tester.element(find.byType(TextField))).platform,
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byType(Switch));
|
||||
await tester.pumpAndSettle();
|
||||
expect(enabled, isTrue);
|
||||
await tester.enterText(find.byType(TextField), '125');
|
||||
expect(find.text('125'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('brief loading finishes without showing the indicator', (
|
||||
tester,
|
||||
) async {
|
||||
const indicator = Key('loading-indicator');
|
||||
await tester.pumpWidget(
|
||||
const DelayedLoadingIndicator(child: SizedBox(key: indicator)),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(find.byKey(indicator), findsNothing);
|
||||
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(find.byKey(indicator), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('slow loading shows the indicator after the shared delay', (
|
||||
tester,
|
||||
) async {
|
||||
const indicator = Key('loading-indicator');
|
||||
await tester.pumpWidget(
|
||||
const DelayedLoadingIndicator(child: SizedBox(key: indicator)),
|
||||
);
|
||||
await tester.pump(DelayedLoadingIndicator.delay);
|
||||
await tester.pump();
|
||||
expect(find.byKey(indicator), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
const channel = MethodChannel('cutdex_native/context_menu');
|
||||
setUp(() => debugDefaultTargetPlatformOverride = TargetPlatform.macOS);
|
||||
tearDown(() {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
});
|
||||
|
||||
test(
|
||||
'native entries preserve nested actions, disabled items and coordinates',
|
||||
() async {
|
||||
var invoked = false;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
expect(call.method, 'show');
|
||||
final args = call.arguments as Map;
|
||||
expect(args['x'], 120.0);
|
||||
expect(args['y'], 80.0);
|
||||
final items = args['items'] as List;
|
||||
expect(items[0]['enabled'], false);
|
||||
expect(items[1]['separator'], true);
|
||||
expect(items[2]['children'][0]['selected'], true);
|
||||
return 1;
|
||||
});
|
||||
expect(
|
||||
await showNativeContextMenu(
|
||||
[
|
||||
const AppMenuItem(label: 'Disabled'),
|
||||
const AppMenuSeparator(),
|
||||
AppSubmenu(
|
||||
label: 'More',
|
||||
items: [
|
||||
AppMenuItem(
|
||||
label: 'Selected',
|
||||
selected: true,
|
||||
onPressed: () => invoked = true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const Offset(120, 80),
|
||||
() => true,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(invoked, isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test('dismissal and disposed owners do not invoke actions', () async {
|
||||
var invoked = false;
|
||||
final items = [
|
||||
AppMenuItem(label: 'Action', onPressed: () => invoked = true),
|
||||
];
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (_) async => null);
|
||||
expect(await showNativeContextMenu(items, Offset.zero, () => true), isTrue);
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (_) async => 0);
|
||||
expect(
|
||||
await showNativeContextMenu(items, Offset.zero, () => false),
|
||||
isTrue,
|
||||
);
|
||||
expect(invoked, isFalse);
|
||||
});
|
||||
|
||||
test('missing native plugin falls back to Flutter', () async {
|
||||
expect(
|
||||
await showNativeContextMenu(
|
||||
[const AppMenuItem(label: 'Action')],
|
||||
Offset.zero,
|
||||
() => true,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('active resource progress omits a redundant status suffix', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ResourceDownloadProgress(
|
||||
downloadedBytes: 7100000,
|
||||
totalBytes: 618000000,
|
||||
status: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('0 B/s - 7.1 MB/618 MB'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('progress displays the download speed supplied by the task', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ResourceDownloadProgress(
|
||||
downloadedBytes: 7100000,
|
||||
totalBytes: 618000000,
|
||||
bytesPerSecond: 1200000,
|
||||
status: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('1.2 MB/s - 7.1 MB/618 MB'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('resource download shows byte progress above a thin track', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: const Scaffold(
|
||||
body: SizedBox(
|
||||
width: 300,
|
||||
child: ResourceDownloadProgress(
|
||||
downloadedBytes: 7100000,
|
||||
totalBytes: 618000000,
|
||||
status: '已暂停',
|
||||
paused: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final label = find.text('7.1 MB/618 MB, 已暂停');
|
||||
final bar = find.byType(LinearProgressIndicator);
|
||||
expect(label, findsOneWidget);
|
||||
expect(tester.getRect(label).bottom, lessThan(tester.getRect(bar).top));
|
||||
final indicator = tester.widget<LinearProgressIndicator>(bar);
|
||||
expect(indicator.value, closeTo(7.1 / 618, 0.00001));
|
||||
expect(indicator.minHeight, 3);
|
||||
expect(indicator.backgroundColor, AppTheme.penDark.dividerColor);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user