332 lines
11 KiB
Dart
332 lines
11 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../run_pipeline_intent.dart';
|
|
import 'run_pipeline_wording.dart';
|
|
|
|
/// The dialog's three web fields, in the host's native controls.
|
|
///
|
|
/// A confirmed launch locks every field: the request is immutable until its
|
|
/// admission is known, exactly like the browser's disabled inputs.
|
|
class RunPipelineFields extends StatelessWidget {
|
|
const RunPipelineFields({
|
|
super.key,
|
|
required this.prompt,
|
|
required this.workspace,
|
|
required this.directories,
|
|
required this.cupertino,
|
|
required this.onChooseDirectory,
|
|
required this.notifyMode,
|
|
required this.outputFormat,
|
|
required this.locked,
|
|
required this.onNotifyChanged,
|
|
required this.onOutputFormatChanged,
|
|
});
|
|
|
|
final TextEditingController prompt;
|
|
final TextEditingController workspace;
|
|
final List<String> directories;
|
|
final bool cupertino;
|
|
final ValueChanged<String> onChooseDirectory;
|
|
final RunNotifyMode notifyMode;
|
|
final RunOutputFormat outputFormat;
|
|
final bool locked;
|
|
final ValueChanged<RunNotifyMode> onNotifyChanged;
|
|
final ValueChanged<RunOutputFormat> onOutputFormatChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = usesCupertinoHost(context);
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
_FieldLabel(runPipelinePromptLabel, cupertino: cupertino),
|
|
_promptField(context, cupertino),
|
|
const SizedBox(height: 12),
|
|
_FieldLabel(runPipelineWorkspaceLabel, cupertino: cupertino),
|
|
_workspaceField(context, cupertino),
|
|
_helper(context, runPipelineWorkspaceHelper, cupertino),
|
|
const SizedBox(height: 12),
|
|
_FieldLabel(runPipelineNotifyLabel, cupertino: cupertino),
|
|
_notifyField(context, cupertino),
|
|
const SizedBox(height: 12),
|
|
_FieldLabel(runPipelineOutputFormatLabel, cupertino: cupertino),
|
|
_outputFormatField(context, cupertino),
|
|
_helper(context, runPipelineOutputFormatHelper, cupertino),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _promptField(BuildContext context, bool cupertino) {
|
|
if (cupertino) {
|
|
return CupertinoTextField(
|
|
key: runPipelinePromptKey,
|
|
controller: prompt,
|
|
placeholder: runPipelinePromptPlaceholder,
|
|
placeholderStyle: _cupertinoPlaceholder(context),
|
|
style: CupertinoTheme.of(context).textTheme.textStyle,
|
|
minLines: 3,
|
|
maxLines: 5,
|
|
enabled: !locked,
|
|
autofocus: !locked,
|
|
padding: const EdgeInsets.all(8),
|
|
textCapitalization: TextCapitalization.sentences,
|
|
);
|
|
}
|
|
return TextField(
|
|
key: runPipelinePromptKey,
|
|
controller: prompt,
|
|
enabled: !locked,
|
|
autofocus: !locked,
|
|
minLines: 3,
|
|
maxLines: 5,
|
|
textCapitalization: TextCapitalization.sentences,
|
|
decoration: const InputDecoration(
|
|
hintText: runPipelinePromptPlaceholder,
|
|
border: OutlineInputBorder(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _workspaceField(BuildContext context, bool cupertino) {
|
|
final field = cupertino
|
|
? _cupertinoWorkspace(context)
|
|
: _materialWorkspace();
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(child: field),
|
|
if (directories.isNotEmpty)
|
|
cupertino
|
|
? CupertinoButton(
|
|
key: runPipelineWorkspaceSuggestionsKey,
|
|
padding: EdgeInsets.zero,
|
|
onPressed: locked
|
|
? null
|
|
: () => _chooseCupertinoDirectory(context),
|
|
child: const Icon(CupertinoIcons.folder),
|
|
)
|
|
: PopupMenuButton<String>(
|
|
key: runPipelineWorkspaceSuggestionsKey,
|
|
tooltip: runPipelineWorkspaceLabel,
|
|
enabled: !locked,
|
|
onSelected: onChooseDirectory,
|
|
itemBuilder: (_) => [
|
|
for (final path in directories)
|
|
PopupMenuItem(value: path, child: Text(path)),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _cupertinoWorkspace(BuildContext context) {
|
|
return CupertinoTextField(
|
|
key: runPipelineWorkspaceKey,
|
|
controller: workspace,
|
|
placeholder: runPipelineWorkspacePlaceholder,
|
|
placeholderStyle: _cupertinoPlaceholder(context),
|
|
style: CupertinoTheme.of(context).textTheme.textStyle,
|
|
enabled: !locked,
|
|
autocorrect: false,
|
|
padding: const EdgeInsets.all(8),
|
|
);
|
|
}
|
|
|
|
Widget _materialWorkspace() {
|
|
return TextField(
|
|
key: runPipelineWorkspaceKey,
|
|
controller: workspace,
|
|
enabled: !locked,
|
|
autocorrect: false,
|
|
decoration: const InputDecoration(
|
|
hintText: runPipelineWorkspacePlaceholder,
|
|
border: OutlineInputBorder(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _chooseCupertinoDirectory(BuildContext context) async {
|
|
final chosen = await showCupertinoModalPopup<String>(
|
|
context: context,
|
|
builder: (sheetContext) => CupertinoActionSheet(
|
|
title: const Text(runPipelineWorkspaceLabel),
|
|
actions: [
|
|
for (final path in directories)
|
|
CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.of(sheetContext).pop(path),
|
|
child: Text(path),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.of(sheetContext).pop(),
|
|
child: const Text(runPipelineCancelLabel),
|
|
),
|
|
),
|
|
);
|
|
if (chosen != null) onChooseDirectory(chosen);
|
|
}
|
|
|
|
Widget _notifyField(BuildContext context, bool cupertino) {
|
|
if (cupertino) {
|
|
return CupertinoButton(
|
|
key: runPipelineNotifyKey,
|
|
padding: EdgeInsets.zero,
|
|
alignment: AlignmentDirectional.centerStart,
|
|
onPressed: locked ? null : () => _chooseNotify(context),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Flexible(child: Text(notifyMode.label)),
|
|
const SizedBox(width: 4),
|
|
const Icon(CupertinoIcons.chevron_down, size: 14),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
return DropdownButtonFormField<RunNotifyMode>(
|
|
key: runPipelineNotifyKey,
|
|
initialValue: notifyMode,
|
|
decoration: const InputDecoration(border: OutlineInputBorder()),
|
|
items: [
|
|
for (final mode in RunNotifyMode.values)
|
|
DropdownMenuItem(value: mode, child: Text(mode.label)),
|
|
],
|
|
onChanged: locked
|
|
? null
|
|
: (mode) {
|
|
if (mode != null) onNotifyChanged(mode);
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> _chooseNotify(BuildContext context) async {
|
|
final chosen = await showCupertinoModalPopup<RunNotifyMode>(
|
|
context: context,
|
|
builder: (sheetContext) => CupertinoActionSheet(
|
|
title: const Text(runPipelineNotifyLabel),
|
|
actions: [
|
|
for (final mode in RunNotifyMode.values)
|
|
CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.of(sheetContext).pop(mode),
|
|
child: Text(mode.label),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
isDefaultAction: true,
|
|
onPressed: () => Navigator.of(sheetContext).pop(),
|
|
child: const Text(runPipelineCancelLabel),
|
|
),
|
|
),
|
|
);
|
|
if (chosen != null) onNotifyChanged(chosen);
|
|
}
|
|
|
|
Widget _outputFormatField(BuildContext context, bool cupertino) {
|
|
if (cupertino) {
|
|
return CupertinoButton(
|
|
key: runPipelineOutputFormatKey,
|
|
padding: EdgeInsets.zero,
|
|
alignment: AlignmentDirectional.centerStart,
|
|
onPressed: locked ? null : () => _chooseOutputFormat(context),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Flexible(child: Text(outputFormat.label)),
|
|
const SizedBox(width: 4),
|
|
const Icon(CupertinoIcons.chevron_down, size: 14),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
return DropdownButtonFormField<RunOutputFormat>(
|
|
key: runPipelineOutputFormatKey,
|
|
initialValue: outputFormat,
|
|
decoration: const InputDecoration(border: OutlineInputBorder()),
|
|
items: [
|
|
for (final format in RunOutputFormat.values)
|
|
DropdownMenuItem(value: format, child: Text(format.label)),
|
|
],
|
|
onChanged: locked
|
|
? null
|
|
: (format) {
|
|
if (format != null) onOutputFormatChanged(format);
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> _chooseOutputFormat(BuildContext context) async {
|
|
final chosen = await showCupertinoModalPopup<RunOutputFormat>(
|
|
context: context,
|
|
builder: (sheetContext) => CupertinoActionSheet(
|
|
title: const Text(runPipelineOutputFormatLabel),
|
|
actions: [
|
|
for (final format in RunOutputFormat.values)
|
|
CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.of(sheetContext).pop(format),
|
|
child: Text(format.label),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
isDefaultAction: true,
|
|
onPressed: () => Navigator.of(sheetContext).pop(),
|
|
child: const Text(runPipelineCancelLabel),
|
|
),
|
|
),
|
|
);
|
|
if (chosen != null) onOutputFormatChanged(chosen);
|
|
}
|
|
|
|
TextStyle _cupertinoPlaceholder(BuildContext context) {
|
|
// The host's own dynamic placeholder colour (light and dark), resolved for
|
|
// the dialog's inherited Cupertino brightness.
|
|
return TextStyle(
|
|
color: CupertinoColors.placeholderText.resolveFrom(context),
|
|
);
|
|
}
|
|
|
|
Widget _helper(BuildContext context, String text, bool cupertino) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Text(text, style: _secondaryStyle(context, cupertino)),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Secondary copy under a field: the host's own secondary role, never a
|
|
/// borrowed palette or invented point size.
|
|
TextStyle _secondaryStyle(BuildContext context, bool cupertino) {
|
|
if (cupertino) {
|
|
return CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
|
|
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
|
);
|
|
}
|
|
final theme = Theme.of(context);
|
|
return (theme.textTheme.bodySmall ?? const TextStyle()).copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
);
|
|
}
|
|
|
|
/// The label above each native field, using the web's exact words.
|
|
class _FieldLabel extends StatelessWidget {
|
|
const _FieldLabel(this.text, {required this.cupertino});
|
|
|
|
final String text;
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// A theme label role with the primary label colour, matching the app's
|
|
// Cupertino form pattern; secondaryLabel is for helper copy only.
|
|
final style = cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: Theme.of(context).textTheme.labelLarge;
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 4),
|
|
child: Text(text, style: style),
|
|
);
|
|
}
|
|
}
|