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_ = []; @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 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 createState() => ProbeContentState(); } class ProbeContentState extends State { 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( 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( 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( context, builder: (_) => const Padding( padding: EdgeInsets.fromLTRB(24, 8, 24, 24), child: Text('Details body'), ), ), ), _button( 'dialog', () => showDialog( context: context, builder: (_) => const AlertDialog(title: Text('Dialog title')), ), ), _button( 'page', () => Navigator.of(context).push( MaterialPageRoute( 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( key: ValueKey('$id-popup'), onSelected: (value) => setState(() => picked = value), itemBuilder: (_) => const [ PopupMenuItem(value: 'popup', child: Text('Popup item')), ], ), DropdownButton( 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 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; }