Files
pipelines/app/lib/features/chat/ui/sessions/chat_prompt_chooser.dart
T

82 lines
2.3 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'chat_create_fields.dart';
/// Native platform controls for choosing what editable prompt to start with.
class ChatPromptChooser extends StatelessWidget {
const ChatPromptChooser({
super.key,
required this.cupertino,
required this.enabled,
required this.choice,
required this.hasLastUsed,
required this.onEnabled,
required this.onChoice,
});
static const custom = 'custom';
static const careful = 'careful';
static const lastUsed = 'last-used';
final bool cupertino;
final bool enabled;
final String choice;
final bool hasLastUsed;
final ValueChanged<bool> onEnabled;
final ValueChanged<String> onChoice;
@override
Widget build(BuildContext context) {
final choices = <String>[custom, careful, if (hasLastUsed) lastUsed];
String label(String value) => switch (value) {
custom => 'Custom',
careful => 'Careful coding',
lastUsed => 'Last used prompt',
_ => value,
};
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
const Expanded(child: Text('Start with a prompt')),
if (cupertino)
CupertinoSwitch(
key: const Key('chat-create-send-prompt'),
value: enabled,
onChanged: onEnabled,
)
else
Switch(
key: const Key('chat-create-send-prompt'),
value: enabled,
onChanged: onEnabled,
),
],
),
if (enabled)
if (cupertino)
CupertinoPickerField(
fieldKey: const Key('chat-create-prompt-choice'),
label: 'Prompt',
value: choices.contains(choice) ? choice : custom,
values: choices,
labelOf: label,
onSelected: onChoice,
)
else
MaterialPickerField(
fieldKey: const Key('chat-create-prompt-choice'),
label: 'Prompt',
value: choices.contains(choice) ? choice : custom,
values: choices,
labelOf: label,
onSelected: onChoice,
),
],
);
}
}