Files
pipelines/app/tool/capture/window_probe.dart
T
alan 31f495fc18 Add adaptive popup helpers: anchored choice menus and details dialogs
Phase 2b.1 of docs/plans/floating-windows.md. showAppChoiceMenu is a menu
panel anchored to its button on a wide app and a bottom sheet on a phone;
showAppDetails is a dialog or a bottom sheet. Both are on the root
navigator, and the app's width decides, so content in a narrow floating
window still gets desktop popups. The probe window exercises both.
2026-11-10 21:53:35 +00:00

191 lines
5.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:pipelines_app/ui/adaptive/app_popups.dart';
import 'package:pipelines_app/shell/windows/window_entry.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
/// A window kind for tests and for the capture fixture (`?windows=N` opens N
/// of them): every kind of popup and a pushed page, opened from inside a
/// window.
class ProbeWindowKind extends WindowKind {
final closed_ = <String>[];
@override
String get key => 'probe';
@override
bool get serverScoped => false;
@override
IconData get icon => Icons.science_outlined;
@override
Size get minSize => const Size(240, 160);
@override
Rect get defaultFrame => const Rect.fromLTWH(100, 80, 360, 420);
@override
String title(BuildContext context, WindowEntry entry) =>
'Probe ${entry.contentId}';
@override
Widget build(BuildContext context, WindowEntry entry) => ProbeContent(
key: ValueKey('content-${entry.contentId}'),
id: entry.contentId,
);
@override
List<WindowAction> actions(BuildContext context, WindowEntry entry) => [
WindowAction(label: 'Probe action', icon: Icons.star, onPressed: () {}),
];
@override
void closed(WindowEntry entry) => closed_.add(entry.id);
}
const probeTooltipColor = Color(0xFFFF00FF);
class ProbeContent extends StatefulWidget {
const ProbeContent({super.key, required this.id});
final String id;
@override
State<ProbeContent> createState() => ProbeContentState();
}
class ProbeContentState extends State<ProbeContent> {
final text = TextEditingController(text: 'select me');
final menu = MenuController();
int builds = 0;
String? picked;
@override
void dispose() {
text.dispose();
super.dispose();
}
Widget _button(String label, VoidCallback onPressed) => TextButton(
key: ValueKey('${widget.id}-$label'),
onPressed: onPressed,
child: Text(label),
);
@override
Widget build(BuildContext context) {
builds++;
final id = widget.id;
return ListView(
children: [
TextField(key: ValueKey('$id-field'), controller: text),
Tooltip(
message: 'Tip text',
decoration: const BoxDecoration(color: probeTooltipColor),
child: Icon(Icons.info, key: ValueKey('$id-tip')),
),
_button(
'sheet',
() => showModalBottomSheet<void>(
context: context,
builder: (sheet) => SizedBox(
height: 200,
child: TextButton(
onPressed: () => Navigator.of(sheet).pop(),
child: const Text('Sheet item'),
),
),
),
),
Builder(
builder: (anchor) => _button('choice', () async {
final value = await showAppChoiceMenu<String>(
anchor,
builder: (menu) => Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final choice in const ['Choice one', 'Choice two'])
ListTile(
title: Text(choice),
onTap: () => Navigator.of(menu).pop(choice),
),
],
),
);
if (mounted && value != null) setState(() => picked = value);
}),
),
_button(
'details',
() => showAppDetails<void>(
context,
builder: (_) => const Padding(
padding: EdgeInsets.fromLTRB(24, 8, 24, 24),
child: Text('Details body'),
),
),
),
_button(
'dialog',
() => showDialog<void>(
context: context,
builder: (_) => const AlertDialog(title: Text('Dialog title')),
),
),
_button(
'page',
() => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => Scaffold(
appBar: AppBar(title: Text('Page of $id')),
body: const Center(child: Text('Page body')),
),
),
),
),
_button(
'snack',
() => ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Snack text'))),
),
MenuAnchor(
controller: menu,
useRootOverlay: true,
menuChildren: [
MenuItemButton(
onPressed: () => setState(() => picked = 'anchor'),
child: const Text('Anchor item'),
),
],
child: _button('anchor', menu.open),
),
PopupMenuButton<String>(
key: ValueKey('$id-popup'),
onSelected: (value) => setState(() => picked = value),
itemBuilder: (_) => const [
PopupMenuItem(value: 'popup', child: Text('Popup item')),
],
),
DropdownButton<String>(
key: ValueKey('$id-dropdown'),
value: 'one',
onChanged: (value) => setState(() => picked = value),
items: const [
DropdownMenuItem(value: 'one', child: Text('Drop one')),
DropdownMenuItem(value: 'two', child: Text('Drop two')),
],
),
Text('picked: $picked'),
],
);
}
}
WindowManager probeManager() =>
WindowManager(kinds: WindowKinds()..register(ProbeWindowKind()));
/// The capture fixture's windows: `?windows=N` opens N probe windows (not
/// saved); without the parameter the app keeps its own.
WindowManager? probeWindows(Map<String, String> params) {
final count = int.tryParse(params['windows'] ?? '');
if (count == null) return null;
final manager = probeManager();
for (var i = 0; i < count; i++) {
manager.open('probe', String.fromCharCode(0x61 + i));
}
return manager;
}