dsh-Go opens the input into two rows only while focused: the text above, the model / mode / keys below, folding back when focus leaves. ComposerBox keeps the field across the two layouts with a GlobalKey and animates the swap. Model and thinking level are now one control (ModelPill shows "model · effort" and the sheet offers the level after choosing a model); Build/Plan is a separate ModeChip. The draft page uses the same box, with its project chip above it. 0.3.15 (315).
145 lines
3.9 KiB
Dart
145 lines
3.9 KiB
Dart
// The composer's two controls: the model pill (model and thinking level in
|
|
// one group) and, separately, the mode (Build / Plan).
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../api/models.dart';
|
|
import '../model_prefs.dart';
|
|
import '../state.dart';
|
|
import 'model_picker.dart';
|
|
|
|
/// `deepseek-flash · 高` — model and effort together, as dsh-Go shows them.
|
|
class ModelPill extends StatelessWidget {
|
|
final AppState app;
|
|
final ModelRef? model;
|
|
final ValueChanged<ModelRef> onModel;
|
|
|
|
const ModelPill({
|
|
super.key,
|
|
required this.app,
|
|
required this.model,
|
|
required this.onModel,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final info = app.modelInfo(model);
|
|
// The server may name the default level "default"; only a level the
|
|
// catalog lists counts as a choice.
|
|
final effort = model?.variant != null &&
|
|
info != null &&
|
|
info.variants.contains(model!.variant)
|
|
? model!.variant
|
|
: null;
|
|
final name = model == null ? '模型' : app.modelName(model!);
|
|
final label = effort == null ? name : '$name · ${effortLabel(effort)}';
|
|
return _Pill(
|
|
icon: Icons.smart_toy_outlined,
|
|
label: label,
|
|
onTap: () => showModelPickerSheet(
|
|
context,
|
|
app: app,
|
|
model: model,
|
|
onModel: onModel,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The mode is its own control: Build or Plan, not part of the model.
|
|
class ModeChip extends StatelessWidget {
|
|
final AppState app;
|
|
final String agent;
|
|
final ValueChanged<String> onAgent;
|
|
|
|
const ModeChip({
|
|
super.key,
|
|
required this.app,
|
|
required this.agent,
|
|
required this.onAgent,
|
|
});
|
|
|
|
static const _modes = ['build', 'plan'];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final current = agent.isEmpty ? _modes.first : agent;
|
|
return PopupMenuButton<String>(
|
|
tooltip: '模式',
|
|
initialValue: current,
|
|
onSelected: onAgent,
|
|
itemBuilder: (_) {
|
|
final known = [
|
|
for (final a in app.agentList)
|
|
if (a.mode == 'primary' && !a.hidden) a,
|
|
];
|
|
final ids = {
|
|
..._modes,
|
|
for (final a in known) a.id,
|
|
};
|
|
return [
|
|
for (final id in ids)
|
|
PopupMenuItem(
|
|
value: id,
|
|
child: Text(_label(id),
|
|
style: TextStyle(
|
|
fontWeight:
|
|
id == current ? FontWeight.w700 : FontWeight.w400)),
|
|
),
|
|
];
|
|
},
|
|
child: _Pill(
|
|
icon: Icons.tune,
|
|
label: _label(current),
|
|
onTap: null,
|
|
),
|
|
);
|
|
}
|
|
|
|
static String _label(String id) =>
|
|
id.isEmpty ? 'Build' : id[0].toUpperCase() + id.substring(1);
|
|
}
|
|
|
|
class _Pill extends StatelessWidget {
|
|
final IconData icon;
|
|
final String label;
|
|
final VoidCallback? onTap;
|
|
|
|
const _Pill({required this.icon, required this.label, this.onTap});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final scheme = theme.colorScheme;
|
|
return InkWell(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: onTap,
|
|
child: Container(
|
|
constraints: const BoxConstraints(minHeight: 30),
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
|
decoration: ShapeDecoration(
|
|
color: scheme.onSurface.withValues(alpha: 0.07),
|
|
shape: const StadiumBorder(),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: 14, color: theme.hintColor),
|
|
const SizedBox(width: 4),
|
|
Flexible(
|
|
child: Text(
|
|
label,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 12.5,
|
|
color: scheme.onSurface,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|