Files
pipelines/app/lib/features/search/search_screen.dart
T
alan 963adec122 Float glass tab bars everywhere the app has bottom tabs
One floating frosted tab bar (host NavigationBar / CupertinoTabBar in the
shared GlassPill) replaces the NavigationRail, the Cupertino sidebar and the
run detail, stage page and pipeline detail tab strips. Below 600px it spans
the width minus 16px margins; wider it is sized to its tabs at the right edge.
Content keeps the full width, scrolls behind the bar and learns its height as
bottom media padding; lists pad their end clear of it and FABs sit above it.

The bar now sizes itself from its own constraints instead of the screen size,
which fixes the widget_test failure where a MediaQuery without a size gave it
negative width constraints.
2026-10-31 01:50:42 +00:00

258 lines
7.9 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/adaptive/segmented_bar.dart';
import '../../core/api_gateway.dart';
import '../../ui/adaptive/host.dart';
import 'data/search_repository.dart';
import 'domain/search_controller.dart';
import 'domain/search_models.dart';
import 'ui/cupertino_search_body.dart';
import 'ui/search_result_view.dart';
import 'ui/material_search_body.dart';
/// Native omni-search over the Pipelines server: a standard search field, an
/// explicit kind selector, 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 shell's bar names it, so no page 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('');
}
void _selectKind(SearchKind kind) => _controller.selectKind(kind);
bool get _showHint {
final body = _controller.bodyKind;
return body == SearchBodyKind.idle || body == SearchBodyKind.empty;
}
Future<void> _pickKind(BuildContext context) async {
final selected = await showCupertinoModalPopup<SearchKind>(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('Kind'),
actions: [
for (final kind in SearchKind.values)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context, kind),
isDefaultAction: kind == _controller.parsed.kind,
child: Text(kind.label),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
if (selected != null) _selectKind(selected);
}
@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);
return cupertino ? _cupertinoScreen() : _materialScreen();
}
Widget _materialScreen() {
// Results scroll behind a floating tab bar; the list clears it itself.
final body = SafeArea(
bottom: false,
child: SearchArtifactScope(
gateway: widget.gateway,
onOpen: widget.onOpen,
child: MaterialSearchBody(
controller: _controller,
query: _controller.parsed.query,
onOpen: widget.onOpen,
header: _materialHeader(),
),
),
);
if (widget.embedded) return body;
return Scaffold(
extendBodyBehindAppBar: true,
appBar: const SegmentedBar(cupertino: false, title: 'Search'),
body: body,
);
}
Widget _materialHeader() => Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: 8,
children: [
SearchBar(
key: const ValueKey('search.field'),
controller: _text,
autoFocus: true,
hintText: 'Search pipelines, runs and artifacts',
leading: const Icon(Icons.search),
trailing: [
if (_text.text.isNotEmpty)
IconButton(
key: const ValueKey('search.clear'),
onPressed: _clear,
tooltip: 'Clear search',
icon: const Icon(Icons.close),
),
],
textInputAction: TextInputAction.search,
onChanged: _controller.updateQuery,
onSubmitted: (_) => _controller.submit(),
),
InputDecorator(
decoration: const InputDecoration(
labelText: 'Kind',
border: OutlineInputBorder(),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<SearchKind>(
key: const ValueKey('search.kind'),
value: _controller.parsed.kind,
isExpanded: true,
onChanged: (kind) {
if (kind != null) _selectKind(kind);
},
items: [
for (final kind in SearchKind.values)
DropdownMenuItem(value: kind, child: Text(kind.label)),
],
),
),
),
if (_showHint) const Text(_tokenHint),
if (_controller.boundsText case final bounds?) Text(bounds),
],
),
);
Widget _cupertinoScreen() {
final body = SafeArea(
bottom: false,
child: SearchArtifactScope(
gateway: widget.gateway,
onOpen: widget.onOpen,
child: CupertinoSearchBody(
controller: _controller,
query: _controller.parsed.query,
onOpen: widget.onOpen,
header: _cupertinoHeader(context),
),
),
);
if (widget.embedded) return body;
return CupertinoPageScaffold(
navigationBar: const SegmentedBar(cupertino: true, title: 'Search'),
child: body,
);
}
Widget _cupertinoHeader(BuildContext context) => Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: 8,
children: [
CupertinoSearchTextField(
key: const ValueKey('search.field'),
controller: _text,
autofocus: true,
placeholder: 'Search pipelines, runs and artifacts',
onChanged: _controller.updateQuery,
onSubmitted: (_) => _controller.submit(),
onSuffixTap: _clear,
),
Align(
alignment: AlignmentDirectional.centerStart,
child: CupertinoButton(
key: const ValueKey('search.kind'),
padding: EdgeInsets.zero,
onPressed: () => _pickKind(context),
child: Row(
mainAxisSize: MainAxisSize.max,
spacing: 6,
children: [
Expanded(child: Text('Kind: ${_controller.parsed.kind.label}')),
const Icon(CupertinoIcons.chevron_down),
],
),
),
),
if (_showHint) const Text(_tokenHint),
if (_controller.boundsText case final bounds?) Text(bounds),
],
),
);
}
const _tokenHint =
'Filter with t:pipeline or type:artifact (pipeline, run, step, field, '
'artifact, version). Last type wins; choosing Kind replaces it. Quote '
'tokens to search literally.';