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,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';
|
||||
Reference in new issue
Block a user