mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 14:23:42 +00:00
feat: new ui (#1455)
This commit is contained in:
742 files changed
+59951
-5934
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
class ActionIconButton extends StatelessWidget {
|
||||
const ActionIconButton({super.key, required this.icon, required this.color, this.onTap});
|
||||
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return shad.IconButton.ghost(
|
||||
onPressed: onTap,
|
||||
density: shad.ButtonDensity.compact,
|
||||
icon: Icon(icon, color: color, size: 18),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../core/utils/breakpoints.dart';
|
||||
import '../theme/app_design_tokens.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
|
||||
class AppChoiceOption<T extends Object> {
|
||||
const AppChoiceOption({required this.value, required this.label, required this.icon, this.key});
|
||||
|
||||
final T value;
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final String? key;
|
||||
}
|
||||
|
||||
class AppChoiceSegmentedControl<T extends Object> extends StatelessWidget {
|
||||
const AppChoiceSegmentedControl({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.options,
|
||||
required this.onChanged,
|
||||
this.buttonKeyPrefix = 'choice',
|
||||
this.alignment,
|
||||
});
|
||||
|
||||
final T value;
|
||||
final List<AppChoiceOption<T>> options;
|
||||
final ValueChanged<T> onChanged;
|
||||
final String buttonKeyPrefix;
|
||||
final WrapAlignment? alignment;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final desktop = MediaQuery.sizeOf(context).width >= Breakpoints.mobile;
|
||||
return Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
alignment: alignment ?? (desktop ? WrapAlignment.end : WrapAlignment.start),
|
||||
children: [
|
||||
for (final option in options)
|
||||
_ChoiceButton<T>(
|
||||
key: ValueKey('$buttonKeyPrefix-${option.key ?? option.value}'),
|
||||
option: option,
|
||||
selected: option.value == value,
|
||||
palette: palette,
|
||||
onPressed: () => onChanged(option.value),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ChoiceButton<T extends Object> extends StatelessWidget {
|
||||
const _ChoiceButton({
|
||||
super.key,
|
||||
required this.option,
|
||||
required this.selected,
|
||||
required this.palette,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final AppChoiceOption<T> option;
|
||||
final bool selected;
|
||||
final AppPalette palette;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: onPressed,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 140),
|
||||
height: 34,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? palette.itemActiveBg : palette.cardBg,
|
||||
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
|
||||
border: Border.all(color: selected ? palette.textPrimary : palette.border),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(option.icon, size: 15, color: selected ? palette.textPrimary : palette.textSecondary),
|
||||
const SizedBox(width: 7),
|
||||
Text(
|
||||
option.label,
|
||||
style: TextStyle(
|
||||
color: selected ? palette.textPrimary : palette.textSecondary,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import 'package:flutter/material.dart' show Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../theme/app_design_tokens.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
import '../../l10n/l10n.dart';
|
||||
|
||||
class AppHttpHeadersController extends ChangeNotifier {
|
||||
AppHttpHeadersController({Map<String, String>? headers, Iterable<String> defaultNames = const []}) {
|
||||
if (headers != null && headers.isNotEmpty) {
|
||||
_rows.addAll(headers.entries.map((entry) => _HttpHeaderRowControllers(name: entry.key, value: entry.value)));
|
||||
} else {
|
||||
_rows.addAll(defaultNames.map((name) => _HttpHeaderRowControllers(name: name)));
|
||||
}
|
||||
_ensureRow();
|
||||
}
|
||||
|
||||
final List<_HttpHeaderRowControllers> _rows = [];
|
||||
|
||||
void replace(Map<String, String> headers) {
|
||||
for (final row in _rows) {
|
||||
row.dispose();
|
||||
}
|
||||
_rows
|
||||
..clear()
|
||||
..addAll(headers.entries.map((entry) => _HttpHeaderRowControllers(name: entry.key, value: entry.value)));
|
||||
_ensureRow();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Map<String, String> toMap({bool requireValue = false}) {
|
||||
final headers = <String, String>{};
|
||||
for (final row in _rows) {
|
||||
final name = row.name.text.trim();
|
||||
final value = row.value.text.trim();
|
||||
if (name.isNotEmpty && (!requireValue || value.isNotEmpty)) {
|
||||
headers[name] = value;
|
||||
}
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
void add() {
|
||||
_rows.add(_HttpHeaderRowControllers());
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void removeAt(int index) {
|
||||
if (_rows.length == 1) return;
|
||||
_rows.removeAt(index).dispose();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _ensureRow() {
|
||||
if (_rows.isEmpty) {
|
||||
_rows.add(_HttpHeaderRowControllers());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final row in _rows) {
|
||||
row.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class AppHttpHeadersEditor extends StatelessWidget {
|
||||
const AppHttpHeadersEditor({super.key, required this.controller, required this.label, required this.keyPrefix});
|
||||
|
||||
final AppHttpHeadersController controller;
|
||||
final String label;
|
||||
final String keyPrefix;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return Row(
|
||||
key: ValueKey('$keyPrefix-editor'),
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 104,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 13, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: AnimatedBuilder(
|
||||
animation: controller,
|
||||
builder: (context, _) => Column(
|
||||
children: [
|
||||
for (var index = 0; index < controller._rows.length; index++) ...[
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 382,
|
||||
child: _HeaderTextField(
|
||||
key: ValueKey('$keyPrefix-name-$index'),
|
||||
controller: controller._rows[index].name,
|
||||
hintText: context.l10n.httpHeaderName,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
flex: 618,
|
||||
child: _HeaderTextField(
|
||||
key: ValueKey('$keyPrefix-value-$index'),
|
||||
controller: controller._rows[index].value,
|
||||
hintText: context.l10n.httpHeaderValue,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
_HeaderAction(
|
||||
key: ValueKey('$keyPrefix-remove-$index'),
|
||||
icon: Icons.remove,
|
||||
onPressed: controller._rows.length == 1 ? null : () => controller.removeAt(index),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Visibility(
|
||||
visible: index == controller._rows.length - 1,
|
||||
maintainAnimation: true,
|
||||
maintainSize: true,
|
||||
maintainState: true,
|
||||
child: _HeaderAction(
|
||||
key: index == controller._rows.length - 1 ? ValueKey('$keyPrefix-add') : null,
|
||||
icon: Icons.add,
|
||||
onPressed: controller.add,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (index != controller._rows.length - 1) const SizedBox(height: 8),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _HttpHeaderRowControllers {
|
||||
_HttpHeaderRowControllers({String name = '', String value = ''})
|
||||
: name = TextEditingController(text: name),
|
||||
value = TextEditingController(text: value);
|
||||
|
||||
final TextEditingController name;
|
||||
final TextEditingController value;
|
||||
|
||||
void dispose() {
|
||||
name.dispose();
|
||||
value.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class _HeaderTextField extends StatelessWidget {
|
||||
const _HeaderTextField({super.key, required this.controller, required this.hintText});
|
||||
|
||||
final TextEditingController controller;
|
||||
final String hintText;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return shad.TextField(
|
||||
controller: controller,
|
||||
hintText: hintText,
|
||||
filled: true,
|
||||
border: Border.all(color: palette.border),
|
||||
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _HeaderAction extends StatelessWidget {
|
||||
const _HeaderAction({super.key, required this.icon, this.onPressed});
|
||||
|
||||
final IconData icon;
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return shad.GhostButton(
|
||||
density: shad.ButtonDensity.icon,
|
||||
onPressed: onPressed,
|
||||
child: Icon(icon, size: 14, color: palette.textSecondary),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../theme/app_design_tokens.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
import 'app_primary_button.dart';
|
||||
|
||||
enum AppLoadingButtonVariant { secondary, primary, brand }
|
||||
|
||||
class AppLoadingButton extends StatelessWidget {
|
||||
const AppLoadingButton({
|
||||
super.key,
|
||||
required this.onPressed,
|
||||
required this.loading,
|
||||
required this.child,
|
||||
this.icon,
|
||||
this.alignment,
|
||||
this.variant = AppLoadingButtonVariant.secondary,
|
||||
});
|
||||
|
||||
final VoidCallback? onPressed;
|
||||
final bool loading;
|
||||
final Widget child;
|
||||
final Widget? icon;
|
||||
final AlignmentGeometry? alignment;
|
||||
final AppLoadingButtonVariant variant;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final replaceChild = loading && icon == null;
|
||||
final leading = loading && icon != null ? _LoadingIcon(variant: variant) : icon;
|
||||
final effectiveChild = replaceChild ? _LoadingIcon(variant: variant) : child;
|
||||
final effectiveOnPressed = loading ? null : onPressed;
|
||||
|
||||
return switch (variant) {
|
||||
AppLoadingButtonVariant.secondary => shad.SecondaryButton(
|
||||
onPressed: effectiveOnPressed,
|
||||
leading: leading,
|
||||
alignment: alignment,
|
||||
child: effectiveChild,
|
||||
),
|
||||
AppLoadingButtonVariant.primary => AppPrimaryButton(
|
||||
onPressed: effectiveOnPressed,
|
||||
leading: leading,
|
||||
alignment: alignment,
|
||||
child: effectiveChild,
|
||||
),
|
||||
AppLoadingButtonVariant.brand => shad.ButtonStyleOverride(
|
||||
decoration: (context, states, value) {
|
||||
final disabled = states.contains(WidgetState.disabled);
|
||||
final color = loading
|
||||
? palette.brand
|
||||
: disabled
|
||||
? palette.brand.withValues(alpha: 0.38)
|
||||
: states.contains(WidgetState.pressed)
|
||||
? Color.alphaBlend(palette.brandForeground.withValues(alpha: 0.12), palette.brand)
|
||||
: states.contains(WidgetState.hovered)
|
||||
? Color.alphaBlend(palette.brandForeground.withValues(alpha: 0.08), palette.brand)
|
||||
: palette.brand;
|
||||
return BoxDecoration(color: color, borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius));
|
||||
},
|
||||
textStyle: (context, states, value) => value.copyWith(
|
||||
color: states.contains(WidgetState.disabled) && !loading
|
||||
? palette.brandForeground.withValues(alpha: 0.55)
|
||||
: palette.brandForeground,
|
||||
),
|
||||
iconTheme: (context, states, value) => value.copyWith(
|
||||
color: states.contains(WidgetState.disabled) && !loading
|
||||
? palette.brandForeground.withValues(alpha: 0.55)
|
||||
: palette.brandForeground,
|
||||
),
|
||||
child: shad.SecondaryButton(
|
||||
onPressed: effectiveOnPressed,
|
||||
leading: leading,
|
||||
alignment: alignment,
|
||||
child: effectiveChild,
|
||||
),
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class _LoadingIcon extends StatelessWidget {
|
||||
const _LoadingIcon({required this.variant});
|
||||
|
||||
final AppLoadingButtonVariant variant;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final foreground = switch (variant) {
|
||||
AppLoadingButtonVariant.secondary => palette.textMuted,
|
||||
AppLoadingButtonVariant.primary => palette.primaryActionForeground,
|
||||
AppLoadingButtonVariant.brand => palette.brandForeground,
|
||||
};
|
||||
final background = switch (variant) {
|
||||
AppLoadingButtonVariant.secondary => palette.border,
|
||||
AppLoadingButtonVariant.primary || AppLoadingButtonVariant.brand => foreground.withValues(alpha: 0.24),
|
||||
};
|
||||
return Center(
|
||||
child: SizedBox.square(
|
||||
dimension: 14,
|
||||
child: shad.CircularProgressIndicator(size: 14, color: foreground, backgroundColor: background),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
import 'package:flutter/material.dart' show Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../core/utils/breakpoints.dart';
|
||||
import '../services/download_directory_picker.dart';
|
||||
import 'app_tooltip.dart';
|
||||
|
||||
enum AppPathPickerButtonStyle { ghost, outline }
|
||||
|
||||
class AppPathPickerField extends StatefulWidget {
|
||||
const AppPathPickerField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.onPick,
|
||||
this.fieldKey,
|
||||
this.pickerKey,
|
||||
this.hintText,
|
||||
this.desktopWidth,
|
||||
this.filled,
|
||||
this.border,
|
||||
this.borderRadius,
|
||||
this.padding,
|
||||
this.onChanged,
|
||||
this.pickerButtonStyle = AppPathPickerButtonStyle.ghost,
|
||||
}) : platformDownloadDirectory = false,
|
||||
onDirectoryPicked = null,
|
||||
allowAndroidEditing = false;
|
||||
|
||||
const AppPathPickerField.downloadDirectory({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.fieldKey,
|
||||
this.pickerKey,
|
||||
this.hintText,
|
||||
this.desktopWidth,
|
||||
this.onDirectoryPicked,
|
||||
this.allowAndroidEditing = false,
|
||||
this.filled,
|
||||
this.border,
|
||||
this.borderRadius,
|
||||
this.padding,
|
||||
this.onChanged,
|
||||
this.pickerButtonStyle = AppPathPickerButtonStyle.outline,
|
||||
}) : onPick = null,
|
||||
platformDownloadDirectory = true;
|
||||
|
||||
final TextEditingController controller;
|
||||
final VoidCallback? onPick;
|
||||
final Key? fieldKey;
|
||||
final Key? pickerKey;
|
||||
final String? hintText;
|
||||
final double? desktopWidth;
|
||||
final bool? filled;
|
||||
final Border? border;
|
||||
final BorderRadiusGeometry? borderRadius;
|
||||
final EdgeInsetsGeometry? padding;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final AppPathPickerButtonStyle pickerButtonStyle;
|
||||
final bool platformDownloadDirectory;
|
||||
final ValueChanged<String>? onDirectoryPicked;
|
||||
final bool allowAndroidEditing;
|
||||
|
||||
@override
|
||||
State<AppPathPickerField> createState() => _AppPathPickerFieldState();
|
||||
}
|
||||
|
||||
class _AppPathPickerFieldState extends State<AppPathPickerField> {
|
||||
late String _tooltipPath = widget.controller.text.trim();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.controller.addListener(_syncTooltipPath);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant AppPathPickerField oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.controller != widget.controller) {
|
||||
oldWidget.controller.removeListener(_syncTooltipPath);
|
||||
widget.controller.addListener(_syncTooltipPath);
|
||||
_tooltipPath = widget.controller.text.trim();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller.removeListener(_syncTooltipPath);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _syncTooltipPath([String? value]) {
|
||||
final path = (value ?? widget.controller.text).trim();
|
||||
if (path == _tooltipPath || !mounted) return;
|
||||
setState(() => _tooltipPath = path);
|
||||
}
|
||||
|
||||
Future<void> _pickPlatformDirectory() async {
|
||||
final path = await DownloadDirectoryPicker.pick(context, currentPath: widget.controller.text.trim());
|
||||
if (!mounted || path == null || path.isEmpty || path == widget.controller.text) return;
|
||||
widget.controller.text = path;
|
||||
_syncTooltipPath(path);
|
||||
widget.onDirectoryPicked?.call(path);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final desktop = MediaQuery.sizeOf(context).width >= Breakpoints.mobile;
|
||||
final onPick = widget.platformDownloadDirectory
|
||||
? (DownloadDirectoryPicker.canPick ? _pickPlatformDirectory : null)
|
||||
: widget.onPick;
|
||||
return SizedBox(
|
||||
width: desktop ? widget.desktopWidth : double.infinity,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MouseRegion(
|
||||
onEnter: (_) => _syncTooltipPath(),
|
||||
child: AppTooltip(
|
||||
message: _tooltipPath,
|
||||
child: shad.TextField(
|
||||
key: widget.fieldKey,
|
||||
controller: widget.controller,
|
||||
hintText: widget.hintText,
|
||||
readOnly:
|
||||
widget.platformDownloadDirectory &&
|
||||
!DownloadDirectoryPicker.canEditManually(allowAndroidEditing: widget.allowAndroidEditing),
|
||||
filled: widget.filled,
|
||||
border: widget.border,
|
||||
borderRadius: widget.borderRadius,
|
||||
padding: widget.padding,
|
||||
onChanged: widget.onChanged,
|
||||
features: [
|
||||
if (onPick != null && widget.pickerButtonStyle == AppPathPickerButtonStyle.outline)
|
||||
_PathPickerSuffixFeature(pickerKey: widget.pickerKey, onPressed: onPick),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (onPick != null && widget.pickerButtonStyle == AppPathPickerButtonStyle.ghost) ...[
|
||||
const SizedBox(width: 2),
|
||||
shad.GhostButton(
|
||||
key: widget.pickerKey,
|
||||
density: shad.ButtonDensity.icon,
|
||||
onPressed: onPick,
|
||||
child: const Icon(Icons.folder_open_outlined, size: 17),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PathPickerSuffixFeature extends shad.InputFeature {
|
||||
const _PathPickerSuffixFeature({required this.pickerKey, required this.onPressed}) : super(skipFocusTraversal: false);
|
||||
|
||||
final Key? pickerKey;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
@override
|
||||
shad.InputFeatureState createState() => _PathPickerSuffixFeatureState();
|
||||
}
|
||||
|
||||
class _PathPickerSuffixFeatureState extends shad.InputFeatureState<_PathPickerSuffixFeature> {
|
||||
@override
|
||||
Iterable<Widget> buildSuffix() sync* {
|
||||
yield shad.IconButton.outline(
|
||||
key: feature.pickerKey,
|
||||
onPressed: feature.onPressed,
|
||||
icon: const Icon(Icons.folder_open_outlined, size: 17),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../theme/app_design_tokens.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
|
||||
class AppPrimaryButton extends StatelessWidget {
|
||||
const AppPrimaryButton({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.onPressed,
|
||||
this.leading,
|
||||
this.trailing,
|
||||
this.alignment,
|
||||
this.size = shad.ButtonSize.normal,
|
||||
this.density = shad.ButtonDensity.normal,
|
||||
this.shape = shad.ButtonShape.rectangle,
|
||||
this.disableTransition = false,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final VoidCallback? onPressed;
|
||||
final Widget? leading;
|
||||
final Widget? trailing;
|
||||
final AlignmentGeometry? alignment;
|
||||
final shad.ButtonSize size;
|
||||
final shad.ButtonDensity density;
|
||||
final shad.ButtonShape shape;
|
||||
final bool disableTransition;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
|
||||
return shad.ButtonStyleOverride(
|
||||
decoration: (context, states, value) {
|
||||
return BoxDecoration(
|
||||
color: _resolveBackground(palette, states),
|
||||
borderRadius: shape == shad.ButtonShape.circle ? null : BorderRadius.circular(AppDesignTokens.controlRadius),
|
||||
shape: shape == shad.ButtonShape.circle ? BoxShape.circle : BoxShape.rectangle,
|
||||
);
|
||||
},
|
||||
textStyle: (context, states, value) {
|
||||
return value.copyWith(color: _resolveForeground(palette, states));
|
||||
},
|
||||
iconTheme: (context, states, value) {
|
||||
return value.copyWith(color: _resolveForeground(palette, states));
|
||||
},
|
||||
child: shad.PrimaryButton(
|
||||
onPressed: onPressed,
|
||||
leading: leading,
|
||||
trailing: trailing,
|
||||
alignment: alignment,
|
||||
size: size,
|
||||
density: density,
|
||||
shape: shape,
|
||||
disableTransition: disableTransition,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _resolveBackground(AppPalette palette, Set<WidgetState> states) {
|
||||
if (states.contains(WidgetState.disabled)) {
|
||||
return palette.primaryActionBg.withValues(alpha: 0.38);
|
||||
}
|
||||
if (states.contains(WidgetState.pressed)) {
|
||||
return Color.alphaBlend(palette.primaryActionForeground.withValues(alpha: 0.14), palette.primaryActionBg);
|
||||
}
|
||||
if (states.contains(WidgetState.hovered)) {
|
||||
return palette.primaryActionHoverBg;
|
||||
}
|
||||
return palette.primaryActionBg;
|
||||
}
|
||||
|
||||
Color _resolveForeground(AppPalette palette, Set<WidgetState> states) {
|
||||
if (states.contains(WidgetState.disabled)) {
|
||||
return palette.primaryActionForeground.withValues(alpha: 0.55);
|
||||
}
|
||||
return palette.primaryActionForeground;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../theme/app_palette.dart';
|
||||
|
||||
enum AppToastType { info, success, error }
|
||||
|
||||
/// Shows the application's shared toast presentation.
|
||||
///
|
||||
/// Toast width is controlled by the loose global [shad.ToastTheme] constraint:
|
||||
/// short messages stay compact while long messages wrap before becoming wider
|
||||
/// than the configured maximum. Errors and normal notices use the same layout.
|
||||
void showAppToast(BuildContext context, String message, {AppToastType type = AppToastType.info}) {
|
||||
final palette = AppPalette.of(context);
|
||||
final borderColor = switch (type) {
|
||||
AppToastType.error => palette.error.withValues(alpha: 0.55),
|
||||
AppToastType.success || AppToastType.info => palette.border,
|
||||
};
|
||||
shad.showToast(
|
||||
context: context,
|
||||
location: shad.ToastLocation.topCenter,
|
||||
builder: (context, overlay) => Align(
|
||||
alignment: Alignment.topCenter,
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Container(
|
||||
key: const ValueKey('app-toast-content'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: palette.cardBg,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: borderColor),
|
||||
),
|
||||
child: Text(message, style: TextStyle(color: palette.textPrimary, fontSize: 13, height: 1.2)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart' show Tooltip;
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// The single product tooltip primitive.
|
||||
///
|
||||
/// Flutter's tooltip is used intentionally because the shadcn tooltip does not
|
||||
/// currently inherit Gopeed's mixed Shadcn/Material theme consistently.
|
||||
class AppTooltip extends StatelessWidget {
|
||||
const AppTooltip({super.key, required this.message, required this.child});
|
||||
|
||||
final String message;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(message: message, child: child);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export 'app_detail_surface_desktop.dart';
|
||||
export 'app_detail_surface_mobile.dart';
|
||||
@@ -0,0 +1,124 @@
|
||||
import 'package:flutter/material.dart' show Colors, Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../l10n/l10n.dart';
|
||||
import '../../theme/app_design_tokens.dart';
|
||||
import '../../theme/app_palette.dart';
|
||||
import '../app_tooltip.dart';
|
||||
|
||||
class AppDetailDrawer extends StatelessWidget {
|
||||
const AppDetailDrawer({
|
||||
super.key,
|
||||
required this.open,
|
||||
required this.title,
|
||||
required this.onClose,
|
||||
required this.child,
|
||||
this.drawerKey,
|
||||
this.width,
|
||||
});
|
||||
|
||||
final bool open;
|
||||
final String title;
|
||||
final VoidCallback onClose;
|
||||
final Widget child;
|
||||
final Key? drawerKey;
|
||||
final double? width;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final light = shad.Theme.of(context).brightness == Brightness.light;
|
||||
final drawerWidth = width ?? AppDesignTokens.taskDetailsDrawerWidth(MediaQuery.sizeOf(context).width);
|
||||
|
||||
return IgnorePointer(
|
||||
ignoring: !open,
|
||||
child: Stack(
|
||||
children: [
|
||||
AnimatedOpacity(
|
||||
opacity: open ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 180),
|
||||
child: GestureDetector(
|
||||
onTap: onClose,
|
||||
child: ColoredBox(color: Colors.black.withValues(alpha: 0.35), child: const SizedBox.expand()),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: AnimatedSlide(
|
||||
duration: const Duration(milliseconds: 260),
|
||||
curve: Curves.easeOutCubic,
|
||||
offset: open ? Offset.zero : const Offset(1, 0),
|
||||
child: Container(
|
||||
key: drawerKey,
|
||||
width: drawerWidth,
|
||||
decoration: BoxDecoration(
|
||||
color: light ? palette.cardBg : palette.bg,
|
||||
border: Border(
|
||||
left: BorderSide(color: light ? palette.headerDivider : palette.border),
|
||||
top: BorderSide(color: palette.headerDivider),
|
||||
),
|
||||
boxShadow: light
|
||||
? [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.08),
|
||||
blurRadius: 24,
|
||||
offset: const Offset(-8, 0),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
key: const ValueKey('app-detail-drawer-header'),
|
||||
height: AppDesignTokens.contentHeaderHeight,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: palette.headerDivider)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 24, end: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: palette.textPrimary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
AppTooltip(
|
||||
message: context.l10n.close,
|
||||
child: SizedBox.square(
|
||||
dimension: 28,
|
||||
child: shad.IconButton.ghost(
|
||||
key: const ValueKey('app-detail-drawer-close-button'),
|
||||
size: shad.ButtonSize.xSmall,
|
||||
onPressed: onClose,
|
||||
icon: Icon(Icons.close, size: 18, color: palette.textSecondary),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(child: open ? child : const SizedBox.shrink()),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart' show Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../l10n/l10n.dart';
|
||||
import '../../theme/app_palette.dart';
|
||||
import '../app_tooltip.dart';
|
||||
|
||||
class AppDetailPage extends StatelessWidget {
|
||||
const AppDetailPage({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.onBack,
|
||||
required this.child,
|
||||
this.backgroundColor,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final VoidCallback onBack;
|
||||
final Widget child;
|
||||
final Color? backgroundColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final background = backgroundColor ?? palette.bg;
|
||||
|
||||
return shad.Scaffold(
|
||||
backgroundColor: background,
|
||||
child: ColoredBox(
|
||||
color: background,
|
||||
child: Column(
|
||||
children: [
|
||||
SafeArea(
|
||||
bottom: false,
|
||||
child: Container(
|
||||
height: 52,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: palette.border)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 44,
|
||||
child: AppTooltip(
|
||||
message: context.l10n.back,
|
||||
child: shad.IconButton.ghost(
|
||||
key: const ValueKey('app-detail-back-button'),
|
||||
onPressed: onBack,
|
||||
icon: Icon(Icons.arrow_back, size: 20, color: palette.textPrimary),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 17, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 44),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(child: child),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,129 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../theme/app_palette.dart';
|
||||
|
||||
class GopeedAppMark extends StatelessWidget {
|
||||
const GopeedAppMark({super.key, this.size = 24});
|
||||
|
||||
final double size;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return Semantics(
|
||||
label: 'Gopeed',
|
||||
image: true,
|
||||
child: SizedBox.square(
|
||||
dimension: size,
|
||||
child: CustomPaint(
|
||||
painter: _GopeedAppMarkPainter(
|
||||
background: palette.primaryActionBg,
|
||||
foreground: palette.primaryActionForeground,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _GopeedAppMarkPainter extends CustomPainter {
|
||||
const _GopeedAppMarkPainter({required this.background, required this.foreground});
|
||||
|
||||
final Color background;
|
||||
final Color foreground;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final side = size.shortestSide;
|
||||
final bounds = Rect.fromCenter(center: size.center(Offset.zero), width: side, height: side).deflate(side * 0.02);
|
||||
final circle = Path()..addOval(bounds);
|
||||
final backgroundPaint = Paint()
|
||||
..color = background
|
||||
..isAntiAlias = true;
|
||||
final foregroundPaint = Paint()
|
||||
..color = foreground
|
||||
..isAntiAlias = true;
|
||||
canvas.drawPath(circle, backgroundPaint);
|
||||
canvas.save();
|
||||
canvas.clipPath(circle, doAntiAlias: true);
|
||||
|
||||
Offset point(double x, double y) {
|
||||
return Offset(bounds.left + bounds.width * x, bounds.top + bounds.height * y);
|
||||
}
|
||||
|
||||
final cloud = Path()
|
||||
..moveTo(point(-0.02, 0.83).dx, point(-0.02, 0.83).dy)
|
||||
..cubicTo(
|
||||
point(0.04, 0.78).dx,
|
||||
point(0.04, 0.78).dy,
|
||||
point(0.09, 0.75).dx,
|
||||
point(0.09, 0.75).dy,
|
||||
point(0.15, 0.73).dx,
|
||||
point(0.15, 0.73).dy,
|
||||
)
|
||||
..cubicTo(
|
||||
point(0.12, 0.66).dx,
|
||||
point(0.12, 0.66).dy,
|
||||
point(0.13, 0.60).dx,
|
||||
point(0.13, 0.60).dy,
|
||||
point(0.20, 0.57).dx,
|
||||
point(0.20, 0.57).dy,
|
||||
)
|
||||
..cubicTo(
|
||||
point(0.27, 0.54).dx,
|
||||
point(0.27, 0.54).dy,
|
||||
point(0.31, 0.58).dx,
|
||||
point(0.31, 0.58).dy,
|
||||
point(0.35, 0.62).dx,
|
||||
point(0.35, 0.62).dy,
|
||||
)
|
||||
..cubicTo(
|
||||
point(0.46, 0.42).dx,
|
||||
point(0.46, 0.42).dy,
|
||||
point(0.66, 0.40).dx,
|
||||
point(0.66, 0.40).dy,
|
||||
point(0.78, 0.50).dx,
|
||||
point(0.78, 0.50).dy,
|
||||
)
|
||||
..cubicTo(
|
||||
point(0.86, 0.57).dx,
|
||||
point(0.86, 0.57).dy,
|
||||
point(0.87, 0.68).dx,
|
||||
point(0.87, 0.68).dy,
|
||||
point(0.86, 0.75).dx,
|
||||
point(0.86, 0.75).dy,
|
||||
)
|
||||
..cubicTo(
|
||||
point(0.92, 0.76).dx,
|
||||
point(0.92, 0.76).dy,
|
||||
point(0.98, 0.79).dx,
|
||||
point(0.98, 0.79).dy,
|
||||
point(1.03, 0.84).dx,
|
||||
point(1.03, 0.84).dy,
|
||||
);
|
||||
canvas.drawPath(
|
||||
cloud,
|
||||
Paint()
|
||||
..color = foreground
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = side * 0.05
|
||||
..strokeCap = StrokeCap.round
|
||||
..strokeJoin = StrokeJoin.round
|
||||
..isAntiAlias = true,
|
||||
);
|
||||
|
||||
final arrow = Path()
|
||||
..addRect(Rect.fromPoints(point(0.41, 0.66), point(0.59, 0.86)))
|
||||
..moveTo(point(0.31, 0.85).dx, point(0.31, 0.85).dy)
|
||||
..lineTo(point(0.69, 0.85).dx, point(0.69, 0.85).dy)
|
||||
..lineTo(point(0.50, 1.02).dx, point(0.50, 1.02).dy)
|
||||
..close();
|
||||
canvas.drawPath(arrow, foregroundPaint);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_GopeedAppMarkPainter oldDelegate) {
|
||||
return background != oldDelegate.background || foreground != oldDelegate.foreground;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import 'package:flutter/material.dart' show Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../core/utils/breakpoints.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
import 'secondary_navigation_pane.dart';
|
||||
|
||||
class ResponsiveMenuItem<T> {
|
||||
const ResponsiveMenuItem({required this.value, required this.label, required this.icon, this.trailing});
|
||||
|
||||
final T value;
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final String? trailing;
|
||||
}
|
||||
|
||||
class ResponsiveMenuLayout<T> extends StatefulWidget {
|
||||
const ResponsiveMenuLayout({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.items,
|
||||
required this.selectedValue,
|
||||
required this.onSelected,
|
||||
required this.contentBuilder,
|
||||
this.mobileContentTitleBuilder,
|
||||
this.mobileContentVisible = false,
|
||||
this.onMobileBack,
|
||||
this.sidebarFooter,
|
||||
this.mobileBreakpoint = Breakpoints.mobile,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final List<ResponsiveMenuItem<T>> items;
|
||||
final T selectedValue;
|
||||
final ValueChanged<T> onSelected;
|
||||
final Widget Function(BuildContext context, T selectedValue) contentBuilder;
|
||||
final String Function(T selectedValue)? mobileContentTitleBuilder;
|
||||
final bool mobileContentVisible;
|
||||
final VoidCallback? onMobileBack;
|
||||
final Widget? sidebarFooter;
|
||||
final double mobileBreakpoint;
|
||||
|
||||
@override
|
||||
State<ResponsiveMenuLayout<T>> createState() => _ResponsiveMenuLayoutState<T>();
|
||||
}
|
||||
|
||||
class _ResponsiveMenuLayoutState<T> extends State<ResponsiveMenuLayout<T>> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.sizeOf(context).width;
|
||||
final mobile = width < widget.mobileBreakpoint;
|
||||
if (!mobile) {
|
||||
return Row(
|
||||
children: [
|
||||
SecondaryNavigationPane<T>(
|
||||
title: widget.title,
|
||||
items: widget.items
|
||||
.map(
|
||||
(item) => SecondaryNavigationPaneItem<T>(
|
||||
value: item.value,
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
trailing: item.trailing,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
selectedValue: widget.selectedValue,
|
||||
onSelected: widget.onSelected,
|
||||
footer: widget.sidebarFooter,
|
||||
),
|
||||
Expanded(child: widget.contentBuilder(context, widget.selectedValue)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
if (!widget.mobileContentVisible) {
|
||||
return SafeArea(
|
||||
bottom: false,
|
||||
child: SecondaryNavigationPane<T>(
|
||||
title: widget.title,
|
||||
items: widget.items
|
||||
.map(
|
||||
(item) => SecondaryNavigationPaneItem<T>(
|
||||
value: item.value,
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
trailing: item.trailing,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
selectedValue: widget.selectedValue,
|
||||
onSelected: widget.onSelected,
|
||||
footer: widget.sidebarFooter,
|
||||
mobile: true,
|
||||
showDisclosure: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return SafeArea(
|
||||
bottom: false,
|
||||
child: Column(
|
||||
children: [
|
||||
_MobileContentHeader(
|
||||
title: widget.mobileContentTitleBuilder?.call(widget.selectedValue) ?? widget.title,
|
||||
onBack: widget.onMobileBack ?? () {},
|
||||
),
|
||||
Expanded(child: widget.contentBuilder(context, widget.selectedValue)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MobileContentHeader extends StatelessWidget {
|
||||
const _MobileContentHeader({required this.title, required this.onBack});
|
||||
|
||||
final String title;
|
||||
final VoidCallback onBack;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return Container(
|
||||
key: const ValueKey('mobile-content-header'),
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: palette.bg,
|
||||
border: Border(bottom: BorderSide(color: palette.border)),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
shad.GhostButton(
|
||||
density: shad.ButtonDensity.icon,
|
||||
onPressed: onBack,
|
||||
child: Icon(Icons.arrow_back, size: 18, color: palette.textPrimary),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: palette.textPrimary, fontSize: 16, fontWeight: FontWeight.w800),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../core/utils/breakpoints.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
import 'secondary_navigation_pane.dart';
|
||||
|
||||
class ResponsiveNavigationItem<T> {
|
||||
const ResponsiveNavigationItem({required this.value, required this.label, this.icon, this.count});
|
||||
|
||||
final T value;
|
||||
final String label;
|
||||
final IconData? icon;
|
||||
final int? count;
|
||||
}
|
||||
|
||||
class ResponsiveNavigationLayout<T> extends StatelessWidget {
|
||||
const ResponsiveNavigationLayout({
|
||||
super.key,
|
||||
required this.items,
|
||||
required this.selectedValue,
|
||||
required this.onSelected,
|
||||
required this.child,
|
||||
required this.desktopTitle,
|
||||
this.desktopFooter,
|
||||
this.mobileHeader,
|
||||
this.mobileBreakpoint = Breakpoints.mobile,
|
||||
});
|
||||
|
||||
final List<ResponsiveNavigationItem<T>> items;
|
||||
final T selectedValue;
|
||||
final ValueChanged<T> onSelected;
|
||||
final Widget child;
|
||||
final String desktopTitle;
|
||||
final Widget? desktopFooter;
|
||||
final Widget? mobileHeader;
|
||||
final double mobileBreakpoint;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.sizeOf(context).width;
|
||||
final mobile = width < mobileBreakpoint;
|
||||
if (!mobile) {
|
||||
return Row(
|
||||
children: [
|
||||
SecondaryNavigationPane<T>(
|
||||
title: desktopTitle,
|
||||
items: items
|
||||
.map(
|
||||
(item) => SecondaryNavigationPaneItem<T>(
|
||||
value: item.value,
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
trailing: item.count?.toString(),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
selectedValue: selectedValue,
|
||||
onSelected: onSelected,
|
||||
footer: desktopFooter,
|
||||
),
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
?mobileHeader,
|
||||
_MobileNavigationTabs<T>(
|
||||
items: items,
|
||||
selectedValue: selectedValue,
|
||||
onSelected: onSelected,
|
||||
reserveTopSafeArea: mobileHeader == null,
|
||||
),
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MobileNavigationTabs<T> extends StatelessWidget {
|
||||
const _MobileNavigationTabs({
|
||||
required this.items,
|
||||
required this.selectedValue,
|
||||
required this.onSelected,
|
||||
required this.reserveTopSafeArea,
|
||||
});
|
||||
|
||||
final List<ResponsiveNavigationItem<T>> items;
|
||||
final T selectedValue;
|
||||
final ValueChanged<T> onSelected;
|
||||
final bool reserveTopSafeArea;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: palette.bg,
|
||||
border: Border(bottom: BorderSide(color: palette.border)),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: reserveTopSafeArea,
|
||||
bottom: false,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 10),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(3),
|
||||
decoration: BoxDecoration(
|
||||
color: palette.surfaceSoft,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: palette.border),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final item in items)
|
||||
_MobileNavigationTab<T>(
|
||||
item: item,
|
||||
active: item.value == selectedValue,
|
||||
onTap: () => onSelected(item.value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MobileNavigationTab<T> extends StatelessWidget {
|
||||
const _MobileNavigationTab({required this.item, required this.active, required this.onTap});
|
||||
|
||||
final ResponsiveNavigationItem<T> item;
|
||||
final bool active;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final label = item.count == null ? item.label : '${item.label} ${item.count}';
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: onTap,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 140),
|
||||
curve: Curves.easeOutCubic,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(color: active ? palette.cardBg : null, borderRadius: BorderRadius.circular(4)),
|
||||
child: Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: active ? palette.textPrimary : palette.textSecondary,
|
||||
fontSize: 12,
|
||||
fontWeight: active ? FontWeight.w700 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import 'package:flutter/material.dart' show Colors, Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../core/window/app_window_chrome.dart';
|
||||
import '../theme/app_design_tokens.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
|
||||
class SecondaryNavigationPaneItem<T> {
|
||||
const SecondaryNavigationPaneItem({required this.value, required this.label, this.icon, this.trailing});
|
||||
|
||||
final T value;
|
||||
final String label;
|
||||
final IconData? icon;
|
||||
final String? trailing;
|
||||
}
|
||||
|
||||
class SecondaryNavigationPane<T> extends StatelessWidget {
|
||||
const SecondaryNavigationPane({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.items,
|
||||
required this.selectedValue,
|
||||
required this.onSelected,
|
||||
this.footer,
|
||||
this.mobile = false,
|
||||
this.showDisclosure = false,
|
||||
this.width = AppDesignTokens.filterSidebarWidth,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final List<SecondaryNavigationPaneItem<T>> items;
|
||||
final T selectedValue;
|
||||
final ValueChanged<T> onSelected;
|
||||
final Widget? footer;
|
||||
final bool mobile;
|
||||
final bool showDisclosure;
|
||||
final double width;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
return Container(
|
||||
key: const ValueKey('secondary-navigation-pane'),
|
||||
width: mobile ? double.infinity : width,
|
||||
color: palette.sideBg,
|
||||
padding: EdgeInsets.only(
|
||||
top: !mobile && AppWindowChrome.reservesHeaderInset ? AppDesignTokens.windowHeaderHeight : 0,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: AppDesignTokens.contentHeaderHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
title.toUpperCase(),
|
||||
style: TextStyle(
|
||||
color: palette.textMuted,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 2.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDesignTokens.space8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final (index, item) in items.indexed)
|
||||
_SecondaryNavigationPaneItem<T>(
|
||||
key: ValueKey('secondary-navigation-item-$index'),
|
||||
item: item,
|
||||
active: item.value == selectedValue,
|
||||
mobile: mobile,
|
||||
showDisclosure: showDisclosure,
|
||||
onTap: () => onSelected(item.value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (footer != null) ...[const Spacer(), footer!] else const Spacer(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SecondaryNavigationPaneItem<T> extends StatelessWidget {
|
||||
const _SecondaryNavigationPaneItem({
|
||||
super.key,
|
||||
required this.item,
|
||||
required this.active,
|
||||
required this.mobile,
|
||||
required this.showDisclosure,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final SecondaryNavigationPaneItem<T> item;
|
||||
final bool active;
|
||||
final bool mobile;
|
||||
final bool showDisclosure;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final content = MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
constraints: BoxConstraints(minHeight: mobile ? 52 : 0),
|
||||
margin: EdgeInsets.only(bottom: mobile ? 6 : 4),
|
||||
padding: EdgeInsets.symmetric(horizontal: mobile ? 14 : 12, vertical: mobile ? 12 : 8),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? palette.itemActiveBg : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
if (item.icon != null) ...[
|
||||
Icon(item.icon, size: mobile ? 20 : 16, color: active ? palette.textPrimary : palette.textSecondary),
|
||||
SizedBox(width: mobile ? 14 : 12),
|
||||
],
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: active ? palette.textPrimary : palette.textSecondary,
|
||||
fontSize: mobile ? 16 : 14,
|
||||
fontWeight: mobile ? FontWeight.w600 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (item.trailing != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: palette.cardHoverBg,
|
||||
borderRadius: BorderRadius.circular(AppDesignTokens.controlRadius),
|
||||
),
|
||||
child: Text(
|
||||
item.trailing!,
|
||||
style: TextStyle(
|
||||
color: active ? palette.textPrimary : palette.textSecondary,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
)
|
||||
else if (showDisclosure)
|
||||
Icon(Icons.chevron_right, size: mobile ? 19 : 15, color: palette.textMuted),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' hide Column, Expanded, Row;
|
||||
|
||||
typedef VirtualTreeItemBuilder<T> = Widget Function(BuildContext context, VirtualTreeEntry<T> entry);
|
||||
typedef VirtualTreeRowTransitionBuilder<T> =
|
||||
Widget Function(BuildContext context, VirtualTreeEntry<T> entry, Widget row);
|
||||
|
||||
class VirtualTreeEntry<T> {
|
||||
const VirtualTreeEntry({required this.node, required this.depth});
|
||||
|
||||
final TreeItemNode<T> node;
|
||||
final List<TreeNodeDepth> depth;
|
||||
}
|
||||
|
||||
class VirtualTreeView<T> extends StatelessWidget {
|
||||
const VirtualTreeView({
|
||||
super.key,
|
||||
required this.nodes,
|
||||
required this.itemBuilder,
|
||||
this.branchLine = BranchLine.path,
|
||||
this.padding = const EdgeInsets.all(8),
|
||||
this.rowHeight = 28,
|
||||
this.cacheExtent = 280,
|
||||
this.controller,
|
||||
this.itemPadding,
|
||||
this.transitionBuilder,
|
||||
});
|
||||
|
||||
final List<TreeNode<T>> nodes;
|
||||
final VirtualTreeItemBuilder<T> itemBuilder;
|
||||
final BranchLine branchLine;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final double rowHeight;
|
||||
final double cacheExtent;
|
||||
final ScrollController? controller;
|
||||
final EdgeInsetsGeometry? itemPadding;
|
||||
final VirtualTreeRowTransitionBuilder<T>? transitionBuilder;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final entries = _flattenVisibleNodes(nodes);
|
||||
final theme = Theme.of(context);
|
||||
final densityGap = theme.density.baseGap * theme.scaling;
|
||||
|
||||
return ListView.builder(
|
||||
controller: controller,
|
||||
padding: padding,
|
||||
cacheExtent: cacheExtent,
|
||||
itemCount: entries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final entry = entries[index];
|
||||
Widget row = SizedBox(
|
||||
height: rowHeight,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (var depthIndex = 1; depthIndex < entry.depth.length; depthIndex++) ...[
|
||||
SizedBox(width: densityGap),
|
||||
SizedBox(width: densityGap * 2, child: branchLine.build(context, entry.depth, depthIndex)),
|
||||
],
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: itemPadding ?? EdgeInsets.symmetric(horizontal: densityGap, vertical: densityGap * 0.5),
|
||||
child: itemBuilder(context, entry),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final transition = transitionBuilder;
|
||||
if (transition != null) {
|
||||
row = transition(context, entry, row);
|
||||
}
|
||||
return row;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<VirtualTreeEntry<T>> _flattenVisibleNodes<T>(List<TreeNode<T>> nodes) {
|
||||
final entries = <VirtualTreeEntry<T>>[];
|
||||
|
||||
void walk(List<TreeNode<T>> currentNodes, List<TreeNodeDepth> depth) {
|
||||
for (var index = 0; index < currentNodes.length; index++) {
|
||||
final node = currentNodes[index];
|
||||
if (node is TreeRootNode<T>) {
|
||||
walk(node.children, depth);
|
||||
continue;
|
||||
}
|
||||
if (node is! TreeItemNode<T>) continue;
|
||||
final currentDepth = [...depth, TreeNodeDepth(index, currentNodes.length)];
|
||||
entries.add(VirtualTreeEntry(node: node, depth: currentDepth));
|
||||
if (node.expanded) {
|
||||
walk(node.children, currentDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
walk(nodes, const []);
|
||||
return entries;
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
import 'package:flutter/foundation.dart' show TargetPlatform, defaultTargetPlatform;
|
||||
import 'package:flutter/material.dart' show Colors;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../../../core/window/app_window_chrome.dart';
|
||||
import '../../theme/app_design_tokens.dart';
|
||||
import '../../theme/app_palette.dart';
|
||||
|
||||
class DesktopWindowHeader extends StatelessWidget {
|
||||
const DesktopWindowHeader({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!AppWindowChrome.usesCustomChrome) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: AppDesignTokens.windowHeaderHeight,
|
||||
child: const Row(
|
||||
children: [
|
||||
Expanded(child: DragToMoveArea(child: SizedBox.expand())),
|
||||
WindowCaptionControls(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WindowCaptionControls extends StatefulWidget {
|
||||
const WindowCaptionControls({super.key});
|
||||
|
||||
@override
|
||||
State<WindowCaptionControls> createState() => _WindowCaptionControlsState();
|
||||
}
|
||||
|
||||
class _WindowCaptionControlsState extends State<WindowCaptionControls> with WindowListener {
|
||||
static const double _captionGlyphSize = 20;
|
||||
bool _isMaximized = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
windowManager.addListener(this);
|
||||
_refreshState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
windowManager.removeListener(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowMaximize() => _refreshState();
|
||||
|
||||
@override
|
||||
void onWindowUnmaximize() => _refreshState();
|
||||
|
||||
Future<void> _refreshState() async {
|
||||
final value = await windowManager.isMaximized();
|
||||
if (mounted) {
|
||||
setState(() => _isMaximized = value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!AppWindowChrome.usesCustomChrome) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final palette = AppPalette.of(context);
|
||||
final textColor = palette.textSecondary;
|
||||
final isLinux = defaultTargetPlatform == TargetPlatform.linux;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_CaptionControlButton(
|
||||
icon: const _MinimizeGlyph(),
|
||||
foreground: textColor,
|
||||
size: isLinux ? 28 : 30,
|
||||
radius: isLinux ? 999 : 4,
|
||||
background: isLinux ? const Color(0x0DFFFFFF) : Colors.transparent,
|
||||
hoverBackground: isLinux ? const Color(0x1AE95420) : palette.captionButtonHover,
|
||||
hoverForeground: textColor,
|
||||
onPressed: windowManager.minimize,
|
||||
),
|
||||
SizedBox(width: isLinux ? 8 : 4),
|
||||
_CaptionControlButton(
|
||||
icon: _isMaximized ? const _RestoreGlyph() : const _MaximizeGlyph(),
|
||||
foreground: textColor,
|
||||
size: isLinux ? 28 : 30,
|
||||
radius: isLinux ? 999 : 4,
|
||||
background: isLinux ? const Color(0x0DFFFFFF) : Colors.transparent,
|
||||
hoverBackground: isLinux ? const Color(0x1AE95420) : palette.captionButtonHover,
|
||||
hoverForeground: textColor,
|
||||
onPressed: _isMaximized ? windowManager.unmaximize : windowManager.maximize,
|
||||
),
|
||||
SizedBox(width: isLinux ? 8 : 4),
|
||||
_CaptionControlButton(
|
||||
icon: const _CloseGlyph(),
|
||||
foreground: isLinux ? const Color(0xFFE95420) : textColor,
|
||||
background: isLinux ? const Color(0x33E95420) : Colors.transparent,
|
||||
size: isLinux ? 28 : 30,
|
||||
radius: isLinux ? 999 : 4,
|
||||
hoverBackground: isLinux ? const Color(0xFFE95420) : const Color(0xFFE81123),
|
||||
hoverForeground: const Color(0xFFFFFFFF),
|
||||
onPressed: windowManager.close,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CaptionControlButton extends StatefulWidget {
|
||||
const _CaptionControlButton({
|
||||
required this.icon,
|
||||
required this.foreground,
|
||||
required this.onPressed,
|
||||
required this.size,
|
||||
required this.radius,
|
||||
required this.background,
|
||||
this.hoverBackground,
|
||||
this.hoverForeground,
|
||||
});
|
||||
|
||||
final Widget icon;
|
||||
final Color foreground;
|
||||
final VoidCallback onPressed;
|
||||
final double size;
|
||||
final double radius;
|
||||
final Color background;
|
||||
final Color? hoverBackground;
|
||||
final Color? hoverForeground;
|
||||
|
||||
@override
|
||||
State<_CaptionControlButton> createState() => _CaptionControlButtonState();
|
||||
}
|
||||
|
||||
class _CaptionControlButtonState extends State<_CaptionControlButton> {
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final palette = AppPalette.of(context);
|
||||
final background = _hovered ? (widget.hoverBackground ?? palette.captionButtonHover) : widget.background;
|
||||
final foreground = _hovered ? (widget.hoverForeground ?? widget.foreground) : widget.foreground;
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap: widget.onPressed,
|
||||
child: Container(
|
||||
width: widget.size,
|
||||
height: widget.size,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(color: background, borderRadius: BorderRadius.circular(widget.radius)),
|
||||
child: IconTheme(
|
||||
data: IconThemeData(color: foreground),
|
||||
child: Center(child: widget.icon),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MinimizeGlyph extends StatelessWidget {
|
||||
const _MinimizeGlyph();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = IconTheme.of(context).color ?? Colors.white;
|
||||
final size = _WindowCaptionControlsState._captionGlyphSize;
|
||||
return SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: size * 0.72,
|
||||
height: size <= 12 ? 1.2 : 1.6,
|
||||
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(999)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MaximizeGlyph extends StatelessWidget {
|
||||
const _MaximizeGlyph();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = IconTheme.of(context).color ?? Colors.white;
|
||||
final size = _WindowCaptionControlsState._captionGlyphSize;
|
||||
final boxSize = size * 0.62;
|
||||
return SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: boxSize,
|
||||
height: boxSize,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: color, width: size <= 12 ? 0.9 : 0.95),
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RestoreGlyph extends StatelessWidget {
|
||||
const _RestoreGlyph();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = IconTheme.of(context).color ?? Colors.white;
|
||||
final size = _WindowCaptionControlsState._captionGlyphSize;
|
||||
final boxSize = size * 0.56;
|
||||
final topBoxLeft = size * 0.40;
|
||||
final topBoxTop = size * 0.16;
|
||||
final bottomBoxLeft = size * 0.16;
|
||||
final bottomBoxTop = size * 0.40;
|
||||
final borderWidth = size <= 12 ? 1.0 : 1.15;
|
||||
return SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
left: topBoxLeft,
|
||||
top: topBoxTop,
|
||||
child: Container(
|
||||
width: boxSize,
|
||||
height: boxSize,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: color, width: borderWidth),
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: bottomBoxLeft,
|
||||
top: bottomBoxTop,
|
||||
child: Container(
|
||||
width: boxSize,
|
||||
height: boxSize,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
border: Border.all(color: color, width: borderWidth),
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CloseGlyph extends StatelessWidget {
|
||||
const _CloseGlyph();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = IconTheme.of(context).color ?? Colors.white;
|
||||
return SizedBox(
|
||||
width: _WindowCaptionControlsState._captionGlyphSize,
|
||||
height: _WindowCaptionControlsState._captionGlyphSize,
|
||||
child: CustomPaint(painter: _CrossPainter(color)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CrossPainter extends CustomPainter {
|
||||
const _CrossPainter(this.color);
|
||||
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final paint = Paint()
|
||||
..color = color
|
||||
..strokeWidth = size.width <= 12 ? 1.2 : 1.8
|
||||
..strokeCap = StrokeCap.round;
|
||||
canvas.drawLine(
|
||||
Offset(size.width * 0.28, size.height * 0.28),
|
||||
Offset(size.width * 0.72, size.height * 0.72),
|
||||
paint,
|
||||
);
|
||||
canvas.drawLine(
|
||||
Offset(size.width * 0.72, size.height * 0.28),
|
||||
Offset(size.width * 0.28, size.height * 0.72),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _CrossPainter oldDelegate) {
|
||||
return oldDelegate.color != color;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user