3704d98d4d
- Search: field, compact Kind menu and syntax help in the bar's actions pill; bounds shown only when truncated; rows with bold title, kind tag and one muted line; results run behind the bar in a start-aligned 840 column. - AppSearchField: one search field per platform (Search, Schedules, Runs filter). - BarIconButton: whole 44pt/48dp bar actions; Runs, bell and Pipelines icons use the same 44pt targets on Cupertino. - Templates and Schedules pages put Refresh in the bar and use the shared round SegmentedBackButton; Templates shows one Back at a time. - PipelineBackButton is the round segmented Back. - notes/pages-fixes.md records the batch, tests and evidence.
167 lines
5.0 KiB
Dart
167 lines
5.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../core/api_gateway.dart';
|
|
import '../../shell/shell_bar.dart';
|
|
import '../../ui/adaptive/host.dart';
|
|
import '../../ui/adaptive/segmented_bar.dart';
|
|
import 'data/search_repository.dart';
|
|
import 'domain/search_controller.dart';
|
|
import 'ui/cupertino_search_body.dart';
|
|
import 'ui/material_search_body.dart';
|
|
import 'ui/search_bar_controls.dart';
|
|
import 'ui/search_bounds_note.dart';
|
|
import 'ui/search_result_view.dart';
|
|
|
|
/// Native omni-search over the Pipelines server: the search field, a compact
|
|
/// kind menu and the syntax help in the top bar's actions pill, and a flat
|
|
/// result list whose rows open the server's own target through [onOpen]. The
|
|
/// screen never mutates server state and never guesses a route for an unknown
|
|
/// or targetless hit.
|
|
class SearchScreen extends StatefulWidget {
|
|
const SearchScreen({
|
|
super.key,
|
|
required this.gateway,
|
|
required this.onOpen,
|
|
this.cupertino,
|
|
this.embedded = false,
|
|
});
|
|
|
|
final ApiGateway gateway;
|
|
final ValueChanged<JsonMap> onOpen;
|
|
|
|
/// Lets the shell state the surface it composed. When omitted, iOS/macOS use
|
|
/// Cupertino controls and every other platform uses Material.
|
|
final bool? cupertino;
|
|
|
|
/// True as the Search tab: the controls go into the shell's bar.
|
|
final bool embedded;
|
|
|
|
@override
|
|
State<SearchScreen> createState() => _SearchScreenState();
|
|
}
|
|
|
|
class _SearchScreenState extends State<SearchScreen> {
|
|
late final OmniSearchController _controller;
|
|
late final TextEditingController _text;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = OmniSearchController(
|
|
repository: SearchRepository(widget.gateway),
|
|
);
|
|
_text = TextEditingController();
|
|
_controller.addListener(_onState);
|
|
}
|
|
|
|
void _onState() {
|
|
final query = _controller.query;
|
|
if (_text.text != query) {
|
|
_text.value = TextEditingValue(
|
|
text: query,
|
|
selection: TextSelection.collapsed(offset: query.length),
|
|
);
|
|
}
|
|
if (mounted) setState(() {});
|
|
}
|
|
|
|
void _clear() {
|
|
_text.clear();
|
|
_controller.updateQuery('');
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.removeListener(_onState);
|
|
_controller.dispose();
|
|
_text.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Follow the actual host app class first: a CupertinoApp supplies no
|
|
// Material theme, so reading only the platform would pick Material controls
|
|
// inside a Cupertino host on macOS/iOS.
|
|
final cupertino =
|
|
widget.cupertino ??
|
|
(usesCupertinoHost(context) ||
|
|
Theme.of(context).platform == TargetPlatform.iOS ||
|
|
Theme.of(context).platform == TargetPlatform.macOS);
|
|
if (widget.embedded) {
|
|
// The shell's bar carries the controls; without a shell (a bare embed)
|
|
// they lead the results instead.
|
|
if (!ShellBar.available(context)) {
|
|
return _body(cupertino, controls: _controls(cupertino));
|
|
}
|
|
return ShellBar(actions: [_controls(cupertino)], child: _body(cupertino));
|
|
}
|
|
final bar = SegmentedBar(
|
|
cupertino: cupertino,
|
|
title: 'Search',
|
|
actions: [_controls(cupertino)],
|
|
);
|
|
if (cupertino) {
|
|
return CupertinoPageScaffold(navigationBar: bar, child: _body(cupertino));
|
|
}
|
|
return Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: bar,
|
|
body: _body(cupertino),
|
|
);
|
|
}
|
|
|
|
Widget _controls(bool cupertino) => SearchBarControls(
|
|
cupertino: cupertino,
|
|
text: _text,
|
|
kind: _controller.parsed.kind,
|
|
onChanged: _controller.updateQuery,
|
|
onSubmitted: _controller.submit,
|
|
onCleared: _clear,
|
|
onKind: _controller.selectKind,
|
|
);
|
|
|
|
/// The server's result and scan bounds, only when they cut the answer
|
|
/// short: a complete answer needs no statistics.
|
|
Widget _header({Widget? controls}) {
|
|
final bounds = _controller.truncated ? _controller.boundsText : null;
|
|
if (bounds == null && controls == null) return const SizedBox.shrink();
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
spacing: 8,
|
|
children: [
|
|
?controls,
|
|
if (bounds != null)
|
|
SearchBoundsNote(key: searchBoundsKey, text: bounds),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// No top safe area: the results run behind the floating bar and the
|
|
/// scroll view starts them below it.
|
|
Widget _body(bool cupertino, {Widget? controls}) {
|
|
final header = _header(controls: controls);
|
|
return SearchArtifactScope(
|
|
gateway: widget.gateway,
|
|
onOpen: widget.onOpen,
|
|
child: cupertino
|
|
? CupertinoSearchBody(
|
|
controller: _controller,
|
|
query: _controller.parsed.query,
|
|
onOpen: widget.onOpen,
|
|
header: header,
|
|
)
|
|
: MaterialSearchBody(
|
|
controller: _controller,
|
|
query: _controller.parsed.query,
|
|
onOpen: widget.onOpen,
|
|
header: header,
|
|
),
|
|
);
|
|
}
|
|
}
|