feat(app): artifact viewer actions are bottom icons; swipe pages; native download, share and open in browser

This commit is contained in:
2026-10-23 22:43:35 +01:00
parent c248e8eca6
commit dd324d1f92
12 changed files with 476 additions and 97 deletions
@@ -23,8 +23,12 @@ class ArtifactFileActions extends StatefulWidget {
required this.resolved,
this.fetch = fetchArtifact,
this.bridge = const ArtifactFileBridge(),
this.compact = false,
});
/// Icon buttons only (a viewer's bottom bar): no labels and no notices.
final bool compact;
final ArtifactRecord artifact;
final ResolvedArtifactUrl resolved;
final ArtifactFetch fetch;
@@ -74,10 +78,12 @@ class _ArtifactFileActionsState extends State<ArtifactFileActions> {
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: _controller,
builder: (context, _) => _ActionBar(
controller: _controller,
cupertino: usesCupertinoHost(context),
),
builder: (context, _) => widget.compact
? _IconActions(controller: _controller)
: _ActionBar(
controller: _controller,
cupertino: usesCupertinoHost(context),
),
);
}
}
@@ -185,3 +191,85 @@ class _ActionBar extends StatelessWidget {
);
}
}
/// Download and Share as icon buttons; a spinner stands in for the one in
/// progress. A host that cannot download or share simply has no button.
class _IconActions extends StatelessWidget {
const _IconActions({required this.controller});
final ArtifactFileActionsController controller;
@override
Widget build(BuildContext context) {
final busy = controller.busy;
return Row(
mainAxisSize: MainAxisSize.min,
children: [
if (controller.canDownload)
ArtifactIconAction(
key: const Key('artifact-download'),
label: 'Download',
icon: Icons.download_outlined,
cupertinoIcon: CupertinoIcons.arrow_down_to_line,
busy: busy,
onPressed: busy ? null : controller.download,
),
if (controller.canShare)
ArtifactIconAction(
key: const Key('artifact-share'),
label: 'Share',
icon: Icons.share_outlined,
cupertinoIcon: CupertinoIcons.share,
onPressed: busy ? null : controller.share,
),
],
);
}
}
/// One icon-only viewer action with its name as tooltip and accessible label.
class ArtifactIconAction extends StatelessWidget {
const ArtifactIconAction({
super.key,
required this.label,
required this.icon,
required this.cupertinoIcon,
required this.onPressed,
this.busy = false,
});
final String label;
final IconData icon;
final IconData cupertinoIcon;
final VoidCallback? onPressed;
final bool busy;
@override
Widget build(BuildContext context) {
if (usesCupertinoHost(context)) {
return Semantics(
button: true,
label: label,
child: CupertinoButton(
padding: const EdgeInsets.all(8),
onPressed: onPressed,
child: busy
? const CupertinoActivityIndicator(radius: 9)
: Icon(cupertinoIcon),
),
);
}
return IconButton(
tooltip: label,
visualDensity: VisualDensity.compact,
onPressed: onPressed,
icon: busy
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Icon(icon),
);
}
}
@@ -1,6 +1,7 @@
import 'artifact_file.dart';
import 'artifact_transfer_stub.dart'
if (dart.library.js_interop) 'artifact_transfer_web.dart'
if (dart.library.io) 'artifact_transfer_io.dart'
as impl;
/// The outcome of a host file transfer.
@@ -0,0 +1,56 @@
import 'package:file_picker/file_picker.dart';
import 'package:share_plus/share_plus.dart';
import 'artifact_file.dart';
import 'artifact_transfer.dart';
/// Phones and desktops: Download asks where to save the exact bytes (the
/// system "Save as"), Share hands the named file to the share sheet.
bool get artifactDownloadSupported => true;
bool get artifactShareSupported => true;
String get artifactDownloadUnsupportedMessage => '';
String get artifactShareUnsupportedMessage => '';
Future<ArtifactTransferResult> saveArtifactFile(ArtifactFile file) async {
try {
final saved = await FilePicker.saveFile(
fileName: file.name,
bytes: file.bytes,
mimeType: file.mimeType,
);
if (saved == null) {
return const ArtifactTransferResult(ArtifactTransferState.canceled, '');
}
return ArtifactTransferResult(
ArtifactTransferState.saved,
'Saved ${file.name}.',
);
} catch (error) {
return ArtifactTransferResult(
ArtifactTransferState.failed,
'Could not save ${file.name}: $error',
);
}
}
Future<ArtifactTransferResult> shareArtifactFile(ArtifactFile file) async {
try {
final result = await SharePlus.instance.share(
ShareParams(
files: [XFile.fromData(file.bytes, mimeType: file.mimeType)],
fileNameOverrides: [file.name],
),
);
return result.status == ShareResultStatus.dismissed
? const ArtifactTransferResult(ArtifactTransferState.canceled, '')
: const ArtifactTransferResult(ArtifactTransferState.shared, '');
} catch (error) {
return ArtifactTransferResult(
ArtifactTransferState.failed,
'Could not share ${file.name}: $error',
);
}
}