Add command files and enhance session management features
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
import "package:flutter/widgets.dart";
|
||||
import "package:shadcn_flutter/shadcn_flutter.dart" as shad;
|
||||
|
||||
|
||||
// floating pane visual — use inside showDialog, backdrop handled by caller
|
||||
class PaneDialog extends StatelessWidget {
|
||||
const PaneDialog({
|
||||
required this.title,
|
||||
required this.child,
|
||||
this.onClose,
|
||||
this.fillHeight = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final Widget child;
|
||||
final VoidCallback? onClose;
|
||||
final bool fillHeight;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = shad.Theme.of(context).colorScheme;
|
||||
final borderColor = Color.lerp(scheme.border, scheme.foreground, 0.1)!;
|
||||
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.background,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: const [
|
||||
BoxShadow(color: Color(0x26888888), blurRadius: 4, spreadRadius: 2),
|
||||
],
|
||||
),
|
||||
|
||||
child: Stack(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Column(
|
||||
mainAxisSize: fillHeight ? MainAxisSize.max : MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_TitleBar(title: title, borderColor: borderColor, onClose: onClose),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: borderColor, width: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class _TitleBar extends StatelessWidget {
|
||||
const _TitleBar({
|
||||
required this.title,
|
||||
required this.borderColor,
|
||||
this.onClose,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final Color borderColor;
|
||||
final VoidCallback? onClose;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = shad.Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
height: 34,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.secondary,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(8),
|
||||
topRight: Radius.circular(8),
|
||||
),
|
||||
border: Border(bottom: BorderSide(color: borderColor, width: 1)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: shad.TextStyle(
|
||||
color: scheme.secondaryForeground,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (onClose != null) _CloseBtn(onTap: onClose!),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class _CloseBtn extends StatefulWidget {
|
||||
const _CloseBtn({required this.onTap});
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
State<_CloseBtn> createState() => _CloseBtnState();
|
||||
}
|
||||
|
||||
class _CloseBtnState extends State<_CloseBtn> {
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = shad.Theme.of(context).colorScheme;
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
child: TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0, end: _hovered ? 1.0 : 0.0),
|
||||
duration: const Duration(milliseconds: 20),
|
||||
builder: (context, t, _) {
|
||||
return Container(
|
||||
width: 18,
|
||||
height: 18,
|
||||
decoration: BoxDecoration(
|
||||
color: Color.lerp(
|
||||
const Color(0x00000000),
|
||||
scheme.destructive.withValues(alpha: 0.12),
|
||||
t,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: shad.Icon(
|
||||
shad.LucideIcons.x,
|
||||
size: 13,
|
||||
color: Color.lerp(scheme.mutedForeground, scheme.destructive, t),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
import "dart:math" as math;
|
||||
|
||||
import "package:flutter/rendering.dart";
|
||||
import "package:shadcn_flutter/shadcn_flutter.dart" as shad;
|
||||
|
||||
|
||||
bool _isCompactTouch(shad.BuildContext context) {
|
||||
return shad.MediaQuery.sizeOf(context).width < 900;
|
||||
}
|
||||
|
||||
class PanelField {
|
||||
const PanelField({
|
||||
required this.section,
|
||||
required this.label,
|
||||
required this.child,
|
||||
this.enabled = true,
|
||||
});
|
||||
|
||||
final String section;
|
||||
final shad.Widget label;
|
||||
final shad.Widget child;
|
||||
final bool enabled;
|
||||
}
|
||||
|
||||
// auto-groups fields by section and renders them as PanelSection > PanelRow
|
||||
class PanelList extends shad.StatelessWidget {
|
||||
const PanelList({super.key, required this.fields});
|
||||
|
||||
final List<PanelField> fields;
|
||||
|
||||
@override
|
||||
shad.Widget build(shad.BuildContext context) {
|
||||
final theme = shad.Theme.of(context);
|
||||
|
||||
final Map<String, List<PanelField>> grouped = {};
|
||||
for (final f in fields) {
|
||||
grouped.putIfAbsent(f.section, () => []).add(f);
|
||||
}
|
||||
|
||||
final entries = grouped.entries.toList();
|
||||
|
||||
return shad.Column(
|
||||
crossAxisAlignment: shad.CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (int i = 0; i < entries.length; i++) ...[
|
||||
PanelSection(
|
||||
title: entries[i].key,
|
||||
children: entries[i]
|
||||
.value
|
||||
.map((f) => PanelRow(label: f.label, child: f.child, enabled: f.enabled))
|
||||
.toList(),
|
||||
),
|
||||
|
||||
if (i < entries.length - 1)
|
||||
shad.Divider(color: theme.colorScheme.border, height: 1),
|
||||
],
|
||||
shad.Divider(color: theme.colorScheme.border, height: 1),
|
||||
const shad.SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PanelSection extends shad.StatefulWidget {
|
||||
const PanelSection({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.children,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final List<shad.Widget> children;
|
||||
|
||||
@override
|
||||
shad.State<PanelSection> createState() => _PanelSectionState();
|
||||
}
|
||||
|
||||
class _PanelSectionState extends shad.State<PanelSection> {
|
||||
bool _expanded = true;
|
||||
|
||||
@override
|
||||
shad.Widget build(shad.BuildContext context) {
|
||||
final theme = shad.Theme.of(context);
|
||||
|
||||
return shad.Column(
|
||||
crossAxisAlignment: shad.CrossAxisAlignment.start,
|
||||
children: [
|
||||
shad.SizedBox(
|
||||
child: shad.GestureDetector(
|
||||
onTap: () => setState(() => _expanded = !_expanded),
|
||||
behavior: shad.HitTestBehavior.opaque,
|
||||
child: shad.ColoredBox(
|
||||
color: theme.colorScheme.secondary,
|
||||
child: shad.Padding(
|
||||
padding: const shad.EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
child: shad.Row(
|
||||
children: [
|
||||
shad.AnimatedRotation(
|
||||
turns: _expanded ? 0.0 : -0.25,
|
||||
duration: const Duration(milliseconds: 120),
|
||||
child: shad.Icon(
|
||||
shad.LucideIcons.chevronDown,
|
||||
size: 12,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
),
|
||||
const shad.SizedBox(width: 4),
|
||||
shad.Text(
|
||||
widget.title,
|
||||
style: shad.TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: shad.FontWeight.w600,
|
||||
color: theme.colorScheme.foreground,
|
||||
letterSpacing: 0.4,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
shad.Divider(color: theme.colorScheme.border, height: 1),
|
||||
if (_expanded)
|
||||
shad.Column(
|
||||
crossAxisAlignment: shad.CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (int i = 0; i < widget.children.length; i++) ...[
|
||||
widget.children[i],
|
||||
if (i < widget.children.length - 1)
|
||||
shad.Divider(color: theme.colorScheme.border, height: 1),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PanelRow extends shad.StatelessWidget {
|
||||
const PanelRow({super.key, required this.label, required this.child, this.enabled = true});
|
||||
|
||||
final shad.Widget label;
|
||||
final shad.Widget child;
|
||||
final bool enabled;
|
||||
|
||||
@override
|
||||
shad.Widget build(shad.BuildContext context) {
|
||||
final isCompactTouch = _isCompactTouch(context);
|
||||
final theme = shad.Theme.of(context);
|
||||
|
||||
final row = shad.ConstrainedBox(
|
||||
constraints: shad.BoxConstraints(minHeight: isCompactTouch ? 52 : 38),
|
||||
child: shad.IntrinsicHeight(
|
||||
child: shad.Padding(
|
||||
padding: const shad.EdgeInsets.only(left: 12),
|
||||
child: shad.Row(
|
||||
crossAxisAlignment: shad.CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
shad.SizedBox(
|
||||
width: 100,
|
||||
child: shad.Align(
|
||||
alignment: shad.Alignment.centerLeft,
|
||||
child: shad.Padding(
|
||||
padding: shad.EdgeInsets.symmetric(vertical: isCompactTouch ? 6 : 4),
|
||||
child: shad.DefaultTextStyle.merge(
|
||||
style: shad.TextStyle(
|
||||
fontSize: 11,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
decoration: !enabled ? shad.TextDecoration.lineThrough : null,
|
||||
decorationThickness: !enabled ? 3 : null,
|
||||
),
|
||||
child: label,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
shad.VerticalDivider(color: theme.colorScheme.border, width: 1),
|
||||
shad.Expanded(
|
||||
child: shad.Padding(
|
||||
padding: shad.EdgeInsets.zero,
|
||||
child: shad.Stack(
|
||||
children: [
|
||||
shad.Positioned.fill(
|
||||
child: shad.Padding(
|
||||
padding: shad.EdgeInsets.symmetric(vertical: isCompactTouch ? 6 : 4, horizontal: 8),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
if (!enabled)
|
||||
shad.Positioned.fill(
|
||||
child: shad.GestureDetector(
|
||||
onTap: () {},
|
||||
behavior: shad.HitTestBehavior.opaque,
|
||||
child: shad.CustomPaint(
|
||||
painter: _DisabledStripePainter(theme.colorScheme.border),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
class _DisabledStripePainter extends CustomPainter {
|
||||
const _DisabledStripePainter(this.color);
|
||||
|
||||
final shad.Color color;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final paint = Paint()
|
||||
..color = color.withValues(alpha: 1)
|
||||
..strokeWidth = 1.0
|
||||
..style = PaintingStyle.stroke;
|
||||
|
||||
const spacing = 4.0;
|
||||
final diag = math.sqrt(size.width * size.width + size.height * size.height);
|
||||
final count = (diag / spacing).ceil() + 2;
|
||||
|
||||
canvas.save();
|
||||
canvas.clipRect(Offset.zero & size);
|
||||
|
||||
canvas.drawRect(Rect.fromLTWH(1, 1, size.width - 3, size.height - 2), paint);
|
||||
|
||||
canvas.translate(0, size.height);
|
||||
canvas.rotate(-math.pi / 4);
|
||||
|
||||
for (int i = -count; i <= count; i++) {
|
||||
final x = i * spacing;
|
||||
canvas.drawLine(Offset(x, -diag), Offset(x, diag), paint);
|
||||
}
|
||||
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_DisabledStripePainter old) => old.color != color;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import "package:provider/provider.dart";
|
||||
import "package:shadcn_flutter/shadcn_flutter.dart";
|
||||
|
||||
import "../../providers/settings_provider.dart";
|
||||
import "../chat/model_picker.dart";
|
||||
import "../chat/models_panel.dart";
|
||||
|
||||
class SettingsSheet extends StatelessWidget {
|
||||
const SettingsSheet();
|
||||
@@ -23,13 +23,7 @@ class SettingsSheet extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// model picker
|
||||
const Text(
|
||||
"Model",
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const ModelPicker(),
|
||||
const ModelsPanel(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// API key setting
|
||||
@@ -64,7 +58,7 @@ class SettingsSheet extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_SimpleDropdown<String>(
|
||||
value: settingsProvider.settings.effortLevel ?? "medium",
|
||||
value: settingsProvider.settings.effortLevel,
|
||||
items: const ["low", "medium", "high", "max"],
|
||||
onChanged: (newLevel) {
|
||||
settingsProvider.updateEffortLevel(newLevel);
|
||||
|
||||
Reference in New Issue
Block a user