2853b18b9e
System default plus Inter, IBM Plex Sans, Source Sans 3 and Atkinson Hyperlegible Next (OFL 1.1, bundled as on-demand assets and loaded with FontLoader, so the web fetches only the previewed/chosen files). Stored in shared_preferences, applied live to Material and Cupertino text themes; RobotoMono styles unchanged. Licences registered with LicenseRegistry.
696 lines
21 KiB
Dart
696 lines
21 KiB
Dart
// Standalone fixture entry for real-browser Search result-selection evidence.
|
|
//
|
|
// Build and probe (from app/):
|
|
// flutter build web --target tool/search_selection_probe_entry.dart \
|
|
// --output build/probe-search-selection
|
|
// node tool/search_selection_probe.mjs --root build/probe-search-selection \
|
|
// --out build/search-selection-probe
|
|
//
|
|
// This is the normal application composition (`PipelinesApp`) over the shared
|
|
// transport, with the socket replaced by an in-process channel that answers
|
|
// the real `search`, `get_run`, `list_runs`, `list_pipelines`, `get_pipeline`
|
|
// and `ping` requests with server-shaped fixtures. Nothing here opens a
|
|
// network connection or touches a live server; the fixtures exist only so the
|
|
// shell's search → run-detail selection can be rendered and captured.
|
|
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:pipelines_app/application/app_url_strategy.dart';
|
|
import 'package:pipelines_app/application/pipelines_app.dart';
|
|
import 'package:pipelines_app/application/bootstrap.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
|
import 'package:pipelines_app/features/search/ui/search_bar_controls.dart'
|
|
show searchFieldKey;
|
|
import 'package:pipelines_app/ui/input/app_search_field.dart';
|
|
import 'package:pipelines_app/ui/theme/app_font.dart';
|
|
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:web_socket_channel/web_socket_channel.dart';
|
|
|
|
import 'fixture_host/fixture_host.dart';
|
|
import 'perf/chat_search_fixture.dart';
|
|
import 'perf/chat_scroll_fixture.dart';
|
|
import 'perf/perf_fixture.dart';
|
|
import 'probe_folder_fixture.dart';
|
|
|
|
/// The run every run-scoped hit names. Its recorded sequences are deliberately
|
|
/// not its row indexes (plan 5, build 2, plan 1), exactly like the unit
|
|
/// fixture, so a selection has to resolve the recorded sequence.
|
|
JsonMap probeRunDetail() => {
|
|
'id': 7,
|
|
'title': 'Release train run',
|
|
'name': 'release-train',
|
|
'status': 'succeeded',
|
|
'created_at': '2026-10-20T08:12:00Z',
|
|
'finished_at': '2026-10-20T08:42:00Z',
|
|
'workspace': '/srv/probe/release',
|
|
'input': {'prompt': 'ship it'},
|
|
'output': {'result': 'ok'},
|
|
'steps': [
|
|
{
|
|
'stage': 'plan',
|
|
'sequence': 5,
|
|
'status': 'completed',
|
|
'outcome': 'success',
|
|
'target': '#success',
|
|
'started_at': '2026-10-20T08:30:00Z',
|
|
'finished_at': '2026-10-20T08:31:00Z',
|
|
'diagnostic': 'release plan accepted',
|
|
'file_changes': _probeChanges(['docs/release-plan.md']),
|
|
},
|
|
{
|
|
'stage': 'build',
|
|
'sequence': 2,
|
|
'status': 'completed',
|
|
'outcome': 'success',
|
|
'target': 'plan',
|
|
'started_at': '2026-10-20T08:16:00Z',
|
|
'finished_at': '2026-10-20T08:24:00Z',
|
|
'artifacts': [
|
|
{
|
|
'name': 'release-report.txt',
|
|
'content_type': 'text/plain',
|
|
'size_bytes': 12,
|
|
'url': '/artifacts/7/2/release-report.txt',
|
|
},
|
|
],
|
|
'file_changes': _probeChanges([
|
|
'lib/release/train.dart',
|
|
'lib/release/notes.dart',
|
|
'test/release/train_test.dart',
|
|
]),
|
|
},
|
|
{
|
|
'stage': 'plan',
|
|
'sequence': 1,
|
|
'status': 'completed',
|
|
'outcome': 'success',
|
|
'target': 'build',
|
|
'started_at': '2026-10-20T08:12:00Z',
|
|
'finished_at': '2026-10-20T08:14:00Z',
|
|
},
|
|
..._fillerSteps(),
|
|
],
|
|
if (perfRunGraph) 'graph': perfRunGraphFixture(),
|
|
};
|
|
|
|
/// A complete change capture modifying [paths], so Changes shows visit pages
|
|
/// and each file opens a paged diff.
|
|
JsonMap _probeChanges(List<String> paths) => {
|
|
'status': 'complete',
|
|
'scope': 'Git tracked and nonignored files in the run directory',
|
|
'skipped': 0,
|
|
'omitted': 0,
|
|
'diagnostic': '',
|
|
'files': [
|
|
for (final path in paths)
|
|
{
|
|
'path': path,
|
|
'kind': 'modified',
|
|
'patch':
|
|
'--- "a/$path"\n'
|
|
'+++ "b/$path"\n'
|
|
'@@ -1,3 +1,3 @@\n'
|
|
' // Release train\n'
|
|
'-const stage = \'draft\';\n'
|
|
'+const stage = \'shipped\';\n'
|
|
' // end\n',
|
|
},
|
|
],
|
|
};
|
|
|
|
/// Extra rows for scroll-performance captures (`?runs=N`, `?steps=N`). Both
|
|
/// default to none, so every other capture sees the fixture unchanged.
|
|
int _fillerRunCount = 0;
|
|
int _fillerStepCount = 0;
|
|
|
|
List<JsonMap> _fillerSteps() => [
|
|
for (var i = 0; i < _fillerStepCount; i++)
|
|
{
|
|
'stage': i.isEven ? 'build' : 'plan',
|
|
'sequence': 100 + i,
|
|
'status': 'completed',
|
|
'outcome': 'success',
|
|
'target': i.isEven ? 'plan' : 'build',
|
|
'started_at': '2026-10-20T08:32:00Z',
|
|
'finished_at': '2026-10-20T08:33:00Z',
|
|
'diagnostic': 'filler step $i for scroll captures',
|
|
},
|
|
];
|
|
|
|
List<JsonMap> _fillerRuns() => [
|
|
for (var i = 0; i < _fillerRunCount; i++)
|
|
{
|
|
'id': 1000 + i,
|
|
'title': 'Filler run $i for scroll captures',
|
|
'name': 'filler-$i',
|
|
'status': i % 3 == 0 ? 'failed' : 'succeeded',
|
|
'created_at': '2026-10-18T08:12:00Z',
|
|
'finished_at': '2026-10-18T08:42:00Z',
|
|
'pipeline_id': i.isEven ? 24 : 22,
|
|
},
|
|
];
|
|
|
|
List<JsonMap> probeRuns() => [
|
|
{
|
|
'id': 7,
|
|
'title': 'Release train run',
|
|
'name': 'release-train',
|
|
'status': 'succeeded',
|
|
'created_at': '2026-10-20T08:12:00Z',
|
|
'finished_at': '2026-10-20T08:42:00Z',
|
|
'pipeline_id': 24,
|
|
},
|
|
{
|
|
'id': 6,
|
|
'title': 'Nightly docs run',
|
|
'name': 'nightly-docs',
|
|
'status': 'failed',
|
|
'created_at': '2026-10-19T22:00:00Z',
|
|
'finished_at': '2026-10-19T22:03:00Z',
|
|
'pipeline_id': 22,
|
|
},
|
|
..._fillerRuns(),
|
|
];
|
|
|
|
List<JsonMap> probePipelines() => [
|
|
{
|
|
'id': 24,
|
|
'name': 'Release train',
|
|
'version': 5,
|
|
'stages': 2,
|
|
'created_at': '2026-09-28T10:12:00',
|
|
'updated_at': '2026-10-20T09:18:00',
|
|
'scheduled': false,
|
|
'schedule_count': 0,
|
|
'enabled_schedule_count': 0,
|
|
},
|
|
{
|
|
'id': 22,
|
|
'name': 'Nightly documentation',
|
|
'version': 6,
|
|
'stages': 1,
|
|
'created_at': '2026-10-02T18:20:00',
|
|
'updated_at': '2026-10-18T16:05:00',
|
|
'scheduled': true,
|
|
'schedule_count': 1,
|
|
'enabled_schedule_count': 1,
|
|
},
|
|
];
|
|
|
|
const _releaseSource =
|
|
'name: Release train\n'
|
|
'stages:\n'
|
|
' plan:\n'
|
|
' type: model\n'
|
|
' output: plan\n'
|
|
' build:\n'
|
|
' type: model\n'
|
|
' output: release\n';
|
|
|
|
JsonMap probePipelineDetail(int id, int requestedVersion) {
|
|
final summary = probePipelines().firstWhere(
|
|
(pipeline) => pipeline['id'] == id,
|
|
orElse: () => probePipelines().first,
|
|
);
|
|
final latest = summary['version'] as int;
|
|
final version = requestedVersion > 0 ? requestedVersion : latest;
|
|
return {
|
|
...summary,
|
|
'version': version,
|
|
'latest_version': latest,
|
|
'version_created_at': '2026-10-18T16:05:00',
|
|
'content_hash': 'sha256:probe-$id-v$version',
|
|
'source': _releaseSource,
|
|
'versions': [
|
|
for (var v = 1; v <= latest; v++)
|
|
{
|
|
'version': v,
|
|
'stages': summary['stages'],
|
|
'created_at': '2026-10-0${v}T10:00:00',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
/// One recorded hit per result kind, each with the text a server would have
|
|
/// matched (`haystack`). The payloads are server-shaped `search_results` rows:
|
|
/// the `target` tokens are the ones `internal/protocol/search.go` records.
|
|
///
|
|
/// `release` matches every kind once; `retired` matches only the retired-field
|
|
/// hit; `missing` matches only an artifact whose recorded visit (sequence 9)
|
|
/// the run never recorded; `first` matches only the plan visit 1 step hit.
|
|
const List<({String haystack, JsonMap hit})> probeHits = [
|
|
(
|
|
haystack: 'Release train pipeline definition',
|
|
hit: {
|
|
'kind': 'pipeline',
|
|
'target': 'pipeline:24',
|
|
'score': 3,
|
|
'recency': '2026-10-20T09:18:00Z',
|
|
'pipeline': {
|
|
'id': 24,
|
|
'name': 'Release train',
|
|
'version': 5,
|
|
'stages': 2,
|
|
},
|
|
},
|
|
),
|
|
(
|
|
haystack: 'name: Nightly documentation release notes',
|
|
hit: {
|
|
'kind': 'version',
|
|
'target': 'pipeline:22:v6',
|
|
'score': 2,
|
|
'recency': '2026-10-18T16:05:00Z',
|
|
'version': {
|
|
'pipeline_id': 22,
|
|
'version': 6,
|
|
'content_hash': '9f2c1ad',
|
|
'created_at': '2026-10-18T16:05:00Z',
|
|
},
|
|
},
|
|
),
|
|
(
|
|
haystack: 'Release train run',
|
|
hit: {
|
|
'kind': 'run',
|
|
'target': 'run:7',
|
|
'score': 2,
|
|
'recency': '2026-10-20T08:42:00Z',
|
|
'run': {
|
|
'id': 7,
|
|
'pipeline_name': 'Release train',
|
|
'status': 'succeeded',
|
|
'workspace': '/srv/probe/release',
|
|
'created_at': '2026-10-20T08:12:00Z',
|
|
'finished_at': '2026-10-20T08:42:00Z',
|
|
},
|
|
},
|
|
),
|
|
(
|
|
haystack: 'release plan accepted',
|
|
hit: {
|
|
'kind': 'step',
|
|
'target': 'run:7:5',
|
|
'score': 1,
|
|
'recency': '2026-10-20T08:31:00Z',
|
|
'step': {
|
|
'run_id': 7,
|
|
'sequence': 5,
|
|
'stage': 'plan',
|
|
'visit': 2,
|
|
'outcome': 'success',
|
|
'target': '#success',
|
|
'diagnostic': 'release plan accepted',
|
|
},
|
|
},
|
|
),
|
|
(
|
|
haystack: 'ship the release',
|
|
hit: {
|
|
'kind': 'field',
|
|
'target': 'run:7:5:output',
|
|
'score': 1,
|
|
'matched_field': 'output',
|
|
'recency': '2026-10-20T08:31:00Z',
|
|
'field': {
|
|
'run_id': 7,
|
|
'sequence': 5,
|
|
'field': 'output',
|
|
'snippet': 'ship the release',
|
|
},
|
|
},
|
|
),
|
|
(
|
|
haystack: 'release-report.txt',
|
|
hit: {
|
|
'kind': 'artifact',
|
|
'target': '/artifacts/7/2/release-report.txt',
|
|
'score': 1,
|
|
'recency': '2026-10-20T08:24:00Z',
|
|
'artifact': {
|
|
'run_id': 7,
|
|
'sequence': 2,
|
|
'name': 'release-report.txt',
|
|
'content_type': 'text/plain',
|
|
'size_bytes': 12,
|
|
'url': '/artifacts/7/2/release-report.txt',
|
|
},
|
|
},
|
|
),
|
|
(
|
|
haystack: 'retired evidence note',
|
|
hit: {
|
|
'kind': 'field',
|
|
'target': 'run:7:5:evidence',
|
|
'score': 1,
|
|
'matched_field': 'evidence',
|
|
'recency': '2026-10-20T08:31:00Z',
|
|
'field': {
|
|
'run_id': 7,
|
|
'sequence': 5,
|
|
'field': 'evidence',
|
|
'snippet': 'retired evidence note',
|
|
},
|
|
},
|
|
),
|
|
(
|
|
haystack: 'missing.log',
|
|
hit: {
|
|
'kind': 'artifact',
|
|
'target': '/artifacts/7/9/missing.log',
|
|
'score': 1,
|
|
'recency': '2026-10-20T08:40:00Z',
|
|
'artifact': {
|
|
'run_id': 7,
|
|
'sequence': 9,
|
|
'name': 'missing.log',
|
|
'content_type': 'text/plain',
|
|
'size_bytes': 4096,
|
|
'url': '/artifacts/7/9/missing.log',
|
|
},
|
|
},
|
|
),
|
|
(
|
|
haystack: 'first plan visit',
|
|
hit: {
|
|
'kind': 'step',
|
|
'target': 'run:7:1',
|
|
'score': 1,
|
|
'recency': '2026-10-20T08:14:00Z',
|
|
'step': {
|
|
'run_id': 7,
|
|
'sequence': 1,
|
|
'stage': 'plan',
|
|
'visit': 1,
|
|
'outcome': 'success',
|
|
'target': 'build',
|
|
},
|
|
},
|
|
),
|
|
];
|
|
|
|
/// Answers one decoded request envelope with the server-shaped reply, or null
|
|
/// for a send-only request the real server does not acknowledge.
|
|
JsonMap? probeReply(JsonMap request) {
|
|
final id = request['id'];
|
|
final type = '${request['type']}';
|
|
JsonMap error(String message) => {
|
|
'id': id,
|
|
'type': 'error',
|
|
'error': message,
|
|
};
|
|
final perf = perfChatReply(request);
|
|
if (perf != null) return perf;
|
|
switch (type) {
|
|
case 'subscribe':
|
|
case 'unsubscribe':
|
|
return null;
|
|
case 'ping':
|
|
return {
|
|
'id': id,
|
|
'type': 'pong',
|
|
'build': {'version': 'Search selection probe fixture'},
|
|
'time': '2026-10-20T09:00:00Z',
|
|
};
|
|
case 'list_runs':
|
|
return {'id': id, 'type': 'runs', 'runs': probeRuns(), 'usage': null};
|
|
case 'get_run':
|
|
if (request['run_id'] != 7) {
|
|
return error('Fixture run ${request['run_id']} is unavailable');
|
|
}
|
|
return {'id': id, 'type': 'run', 'run_detail': probeRunDetail()};
|
|
case 'list_pipelines':
|
|
return {'id': id, 'type': 'pipelines', 'pipelines': probePipelines()};
|
|
case 'get_pipeline':
|
|
final pipelineId = request['pipeline_id'];
|
|
if (pipelineId is! int ||
|
|
!probePipelines().any((pipeline) => pipeline['id'] == pipelineId)) {
|
|
return error('Fixture pipeline $pipelineId is unavailable');
|
|
}
|
|
final version = request['version'];
|
|
return {
|
|
'id': id,
|
|
'type': 'pipeline',
|
|
'detail': probePipelineDetail(pipelineId, version is int ? version : 0),
|
|
};
|
|
case 'search':
|
|
// The app must send exactly the browser's SearchRequest body; anything
|
|
// else is answered with a visible refusal so the capture cannot pass.
|
|
final search = request['search'];
|
|
if (search is! Map ||
|
|
search.length != 3 ||
|
|
search['query'] is! String ||
|
|
search['kind'] is! String ||
|
|
search['limit'] != 0) {
|
|
return error('Fixture refused a malformed search request: $search');
|
|
}
|
|
final query = (search['query'] as String).trim().toLowerCase();
|
|
final kind = search['kind'] as String;
|
|
if (kind == 'chat') {
|
|
// The server answers chats as their own request (search_chats.go).
|
|
return {
|
|
'id': id,
|
|
'type': 'search_results',
|
|
'search_results': {
|
|
'query': search['query'],
|
|
'kind': kind,
|
|
'results': perfChatSearchHits(query),
|
|
'truncated': false,
|
|
'scanned_steps': 0,
|
|
'scanned_bytes': 0,
|
|
'cap': 50,
|
|
'scan_bound_bytes': 1048576,
|
|
'scanned_chats': 3,
|
|
},
|
|
};
|
|
}
|
|
final results = [
|
|
for (final entry in probeHits)
|
|
if ((kind.isEmpty || entry.hit['kind'] == kind) &&
|
|
(query.isEmpty || entry.haystack.toLowerCase().contains(query)))
|
|
entry.hit,
|
|
...perfSearchHits(query, kind),
|
|
];
|
|
return {
|
|
'id': id,
|
|
'type': 'search_results',
|
|
'search_results': {
|
|
'query': search['query'],
|
|
'kind': kind,
|
|
'results': results,
|
|
'truncated': false,
|
|
'scanned_steps': 3,
|
|
'scanned_bytes': 2048,
|
|
'cap': 50,
|
|
'scan_bound_bytes': 1048576,
|
|
},
|
|
};
|
|
default:
|
|
return probeFolderReply(request) ??
|
|
error('Fixture does not implement $type');
|
|
}
|
|
}
|
|
|
|
/// An in-process websocket channel: every frame the client sends is decoded
|
|
/// and answered asynchronously with [probeReply], as the server would over the
|
|
/// wire. `ready` completes at once so the shared client reports connected.
|
|
class _FixtureChannel implements WebSocketChannel {
|
|
_FixtureChannel();
|
|
|
|
final _incoming = StreamController<dynamic>();
|
|
late final _FixtureSink _sink = _FixtureSink(this);
|
|
|
|
@override
|
|
Stream<dynamic> get stream => _incoming.stream;
|
|
|
|
@override
|
|
WebSocketSink get sink => _sink;
|
|
|
|
@override
|
|
Future<void> get ready => Future<void>.value();
|
|
|
|
@override
|
|
String? get protocol => null;
|
|
|
|
@override
|
|
int? get closeCode => null;
|
|
|
|
@override
|
|
String? get closeReason => null;
|
|
|
|
void receive(dynamic data) {
|
|
if (data is! String) return;
|
|
final decoded = jsonDecode(data);
|
|
if (decoded is! Map<String, dynamic>) return;
|
|
final reply = probeReply(decoded);
|
|
final followUps = perfChatFollowUps(decoded);
|
|
final subscribe = decoded['chat_subscribe'];
|
|
if (subscribe is Map) {
|
|
chatScrollStream('${subscribe['session_id'] ?? ''}', (frame) {
|
|
if (!_incoming.isClosed) _incoming.add(jsonEncode(frame));
|
|
});
|
|
}
|
|
if (reply == null && followUps.isEmpty) return;
|
|
Future<void>.delayed(const Duration(milliseconds: 120), () {
|
|
if (_incoming.isClosed) return;
|
|
if (reply != null) _incoming.add(jsonEncode(reply));
|
|
for (final frame in followUps) {
|
|
_incoming.add(jsonEncode(frame));
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> close() async {
|
|
if (!_incoming.isClosed) await _incoming.close();
|
|
}
|
|
|
|
@override
|
|
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
}
|
|
|
|
class _FixtureSink implements WebSocketSink {
|
|
_FixtureSink(this.channel);
|
|
|
|
final _FixtureChannel channel;
|
|
|
|
@override
|
|
void add(dynamic event) => channel.receive(event);
|
|
|
|
@override
|
|
void addError(Object error, [StackTrace? stackTrace]) => throw error;
|
|
|
|
@override
|
|
Future<void> addStream(Stream<dynamic> stream) async {
|
|
await for (final item in stream) {
|
|
add(item);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> close([int? closeCode, String? closeReason]) => channel.close();
|
|
|
|
@override
|
|
Future<void> get done => channel._incoming.done;
|
|
|
|
@override
|
|
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
}
|
|
|
|
/// Static-server capture flags, so a plain file server (no index.html
|
|
/// fallback for `/runs/7`) can still open a deep location:
|
|
///
|
|
/// `?route=/runs/7/stage/build%3Fvisit%3D1` opens that app location;
|
|
/// `?runs=200` / `?steps=60` append filler runs / run-7 steps for scroll
|
|
/// performance captures;
|
|
/// `?q=release` types that query into Search once its field is shown;
|
|
/// `?platform=cupertino` renders the Cupertino host (`material`, the
|
|
/// default, renders Material as browsers do);
|
|
/// `?perf=1` prints frame timings (tool/perf/frame_log.dart);
|
|
/// `?hits=N`, `?chats=N` and `?graph=1` add bench data
|
|
/// (tool/perf/perf_fixture.dart);
|
|
/// `?theme=dark` / `?theme=light` pins the platform brightness the app's
|
|
/// `ThemeMode.system` follows (omitted: the browser's color scheme).
|
|
///
|
|
/// app/tool/capture/ drives this entry generically; see its README.
|
|
void main() {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
final params = fixtureParams();
|
|
installHostProbes(params);
|
|
// `?connect=1` (native only) opens the real launch flow with no saved
|
|
// server, so the Connect screen can be reviewed without any server.
|
|
if (params['connect'] == '1') {
|
|
runPipelinesApp(configured: '');
|
|
return;
|
|
}
|
|
configurePerfFixture(params);
|
|
// `?font=inter` chooses a font as Settings would; otherwise the stored one.
|
|
final font = params['font'];
|
|
unawaited(
|
|
font == null
|
|
? AppFontController.instance.restore()
|
|
: AppFontController.instance.select(AppFont.fromId(font)),
|
|
);
|
|
_fillerRunCount = int.tryParse(params['runs'] ?? '') ?? 0;
|
|
_fillerStepCount = int.tryParse(params['steps'] ?? '') ?? 0;
|
|
final cupertino = params['platform'] == 'cupertino';
|
|
final route = params['route'];
|
|
final opensRoute = route != null && route.startsWith('/');
|
|
if (opensRoute) openFixtureRoute(route, cupertino: cupertino);
|
|
final query = params['q'];
|
|
if (query != null && query.isNotEmpty) _typeSearchWhenShown(query);
|
|
useAppUrlStrategy();
|
|
final app = PipelinesApp(
|
|
server: fixtureServer(params),
|
|
client: PipelinesClient(channelFactory: (_) => _FixtureChannel()),
|
|
cupertino: cupertino,
|
|
routeInformationProvider: fixtureRouteProvider(opensRoute ? route : null),
|
|
);
|
|
final brightness = switch (params['theme']) {
|
|
'dark' => Brightness.dark,
|
|
'light' => Brightness.light,
|
|
_ => null,
|
|
};
|
|
runFixtureApp(
|
|
brightness == null
|
|
? app
|
|
: _PinnedBrightness(brightness: brightness, child: app),
|
|
params,
|
|
);
|
|
}
|
|
|
|
/// Pins the platform brightness below it. The app's own `MediaQuery.fromView`
|
|
/// takes platform fields from this ambient query, so `ThemeMode.system` (and
|
|
/// the Cupertino theme's null brightness) resolve to [brightness] while size,
|
|
/// padding and text scale still follow the real view.
|
|
class _PinnedBrightness extends StatelessWidget {
|
|
const _PinnedBrightness({required this.brightness, required this.child});
|
|
|
|
final Brightness brightness;
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => MediaQuery.fromView(
|
|
view: View.of(context),
|
|
child: Builder(
|
|
builder: (context) => MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(platformBrightness: brightness),
|
|
child: child,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Types [query] into Search's field once it is shown, through the field's
|
|
/// own change and submit callbacks, exactly as typing would.
|
|
void _typeSearchWhenShown(String query) {
|
|
void attempt(Duration _) {
|
|
AppSearchField? found;
|
|
void visit(Element element) {
|
|
if (found != null) return;
|
|
final widget = element.widget;
|
|
if (widget is AppSearchField && widget.fieldKey == searchFieldKey) {
|
|
found = widget;
|
|
return;
|
|
}
|
|
element.visitChildren(visit);
|
|
}
|
|
|
|
WidgetsBinding.instance.rootElement?.visitChildren(visit);
|
|
final field = found;
|
|
if (field == null) {
|
|
WidgetsBinding.instance.addPostFrameCallback(attempt);
|
|
WidgetsBinding.instance.scheduleFrame();
|
|
return;
|
|
}
|
|
field.controller.text = query;
|
|
field.onChanged?.call(query);
|
|
field.onSubmitted?.call(query);
|
|
}
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
WidgetsBinding.instance.addPostFrameCallback(attempt);
|
|
}
|