import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/adaptive/host.dart'; import '../../artifacts/actions/artifact_transfer.dart'; import '../../artifacts/domain/artifact_kind.dart'; import '../../artifacts/ui/artifact_external_open.dart'; import '../data/directory_listing.dart'; import 'files_download.dart'; import 'files_models.dart'; import 'files_preview.dart'; import 'files_urls.dart'; /// Details and host-native actions for a file the embedded viewer cannot show. void showFileDetails( BuildContext context, { required DirectoryEntry entry, required FileUrls? urls, required Future Function()? download, required ArtifactExternalOpen openExternal, }) { final cupertino = usesCupertinoHost(context); Widget content(BuildContext sheet) { Future open() async { var opened = false; try { opened = await openExternal(urls!.view); } catch (_) { /* keep the sheet and download action available */ } if (opened && sheet.mounted) Navigator.pop(sheet); } final body = SafeArea( child: Padding( padding: const EdgeInsets.all(20), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( entry.name, style: cupertino ? CupertinoTheme.of(sheet).textTheme.navTitleTextStyle : Theme.of(sheet).textTheme.titleLarge, ), const SizedBox(height: 12), Text( '${artifactKindLabel(artifactKind(fileContentType(entry.name), entry.name))} ยท ${fileSizeLabel(entry.size)}', ), Text('Modified: ${fileModifiedLabel(entry.modified)}'), const SizedBox(height: 8), Text( urls == null ? 'No server address is configured, so this file cannot be fetched.' : 'This file type cannot be previewed here.', ), const SizedBox(height: 16), if (download != null) FileDownloadButton(download: download), if (urls != null) cupertino ? CupertinoButton( onPressed: open, child: const Text('Open externally'), ) : TextButton.icon( onPressed: open, icon: const Icon(Icons.open_in_new), label: const Text('Open externally'), ), if (cupertino) CupertinoButton( onPressed: () => Navigator.pop(sheet), child: const Text('Close'), ), ], ), ), ); return cupertino ? CupertinoPopupSurface( child: DefaultTextStyle( style: CupertinoTheme.of(sheet).textTheme.textStyle, child: body, ), ) : body; } if (cupertino) { showCupertinoModalPopup(context: context, builder: content); } else { showModalBottomSheet( context: context, showDragHandle: true, builder: content, ); } }