9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
215 lines
6.9 KiB
Dart
215 lines
6.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../domain/artifact_groups.dart';
|
|
import '../domain/artifact_kind.dart';
|
|
import '../domain/artifact_record.dart';
|
|
import '../domain/artifact_url.dart';
|
|
import 'artifact_row_labels.dart';
|
|
import 'artifact_thumbnail_image.dart';
|
|
import 'artifact_viewer_fetch.dart';
|
|
|
|
/// One artifact in the gallery grid: a thumbnail for an image, otherwise an
|
|
/// icon for its kind of file, with its name and facts underneath.
|
|
class ArtifactTile extends StatefulWidget {
|
|
const ArtifactTile({
|
|
super.key,
|
|
required this.group,
|
|
required this.artifact,
|
|
required this.selected,
|
|
required this.configuredEndpoint,
|
|
required this.fetch,
|
|
this.onSelected,
|
|
});
|
|
|
|
final ArtifactGroup group;
|
|
final ArtifactRecord artifact;
|
|
final bool selected;
|
|
final String configuredEndpoint;
|
|
final ArtifactFetch fetch;
|
|
final ArtifactSelected? onSelected;
|
|
|
|
@override
|
|
State<ArtifactTile> createState() => _ArtifactTileState();
|
|
}
|
|
|
|
class _ArtifactTileState extends State<ArtifactTile> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final artifact = widget.artifact;
|
|
final secondary = Theme.of(context).colorScheme.onSurfaceVariant;
|
|
final surface = Theme.of(context).colorScheme.surfaceContainerHighest;
|
|
final border = widget.selected
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.outlineVariant;
|
|
final preview = ArtifactThumbnail(
|
|
artifact: artifact,
|
|
configuredEndpoint: widget.configuredEndpoint,
|
|
fetch: widget.fetch,
|
|
iconSize: 40,
|
|
);
|
|
final name = artifactDisplayName(artifact);
|
|
final facts = artifactFactsLabel(artifact);
|
|
final body = Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
AspectRatio(
|
|
aspectRatio: 4 / 3,
|
|
child: ClipRRect(
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(11)),
|
|
child: ColoredBox(color: surface, child: preview),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 6, 8, 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(name, maxLines: 1, overflow: TextOverflow.ellipsis),
|
|
Text(
|
|
facts,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(color: secondary, fontSize: 12),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
final onSelected = widget.onSelected;
|
|
void tap() => onSelected?.call(widget.group, artifact);
|
|
final decorated = DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: border, width: widget.selected ? 2 : 1),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: body,
|
|
);
|
|
return Semantics(
|
|
button: onSelected != null,
|
|
selected: widget.selected,
|
|
label: '$name, $facts',
|
|
excludeSemantics: true,
|
|
onTap: onSelected == null ? null : tap,
|
|
child: Material(
|
|
type: MaterialType.transparency,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(12),
|
|
onTap: onSelected == null ? null : tap,
|
|
child: decorated,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// An artifact's picture: the image itself, loaded once through the app's own
|
|
/// fetch, or an icon for its kind of file.
|
|
class ArtifactThumbnail extends StatefulWidget {
|
|
const ArtifactThumbnail({
|
|
super.key,
|
|
required this.artifact,
|
|
required this.configuredEndpoint,
|
|
required this.fetch,
|
|
this.iconSize = 24,
|
|
});
|
|
|
|
final ArtifactRecord artifact;
|
|
final String configuredEndpoint;
|
|
final ArtifactFetch fetch;
|
|
final double iconSize;
|
|
|
|
@override
|
|
State<ArtifactThumbnail> createState() => _ArtifactThumbnailState();
|
|
}
|
|
|
|
class _ArtifactThumbnailState extends State<ArtifactThumbnail>
|
|
with AutomaticKeepAliveClientMixin {
|
|
Future<ArtifactFetchResult>? _image;
|
|
|
|
/// A loaded picture stays alive when a lazy gallery scrolls it away, so
|
|
/// scrolling back does not fetch it again.
|
|
@override
|
|
bool get wantKeepAlive => _image != null;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
final artifact = widget.artifact;
|
|
final format = artifactPreviewFormat(artifact.contentType, artifact.name);
|
|
final resolved = artifact.hasUrl
|
|
? resolveArtifactUrl(widget.configuredEndpoint, artifact.url)
|
|
: null;
|
|
// Only same-origin images load a thumbnail, through the app's own fetch.
|
|
if (format == ArtifactPreviewFormat.image &&
|
|
resolved != null &&
|
|
!resolved.external) {
|
|
_image = widget.fetch(resolved.uri);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
super.build(context);
|
|
final icon = Icon(
|
|
artifactKindIcon(widget.artifact),
|
|
size: widget.iconSize,
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
);
|
|
if (_image == null) return Center(child: icon);
|
|
return FutureBuilder<ArtifactFetchResult>(
|
|
future: _image,
|
|
builder: (context, snapshot) {
|
|
final result = snapshot.data;
|
|
if (result == null || !result.ok || result.bytes.isEmpty) {
|
|
return Center(child: icon);
|
|
}
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final ratio = MediaQuery.devicePixelRatioOf(context);
|
|
// Decoded at the size shown, not the picture's full size.
|
|
final sized =
|
|
constraints.hasBoundedWidth && constraints.hasBoundedHeight
|
|
? CoverSizedMemoryImage(
|
|
result.bytes,
|
|
width: (constraints.maxWidth * ratio).ceil(),
|
|
height: (constraints.maxHeight * ratio).ceil(),
|
|
)
|
|
: null;
|
|
return Image(
|
|
image: sized ?? MemoryImage(result.bytes),
|
|
fit: BoxFit.cover,
|
|
gaplessPlayback: true,
|
|
errorBuilder: (_, _, _) => Center(child: icon),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The icon for an artifact's kind of file, when it has no thumbnail.
|
|
///
|
|
/// The Material glyph the app draws for this file kind.
|
|
IconData artifactKindIcon(ArtifactRecord artifact) {
|
|
final name = artifact.name.toLowerCase();
|
|
final format = artifactPreviewFormat(artifact.contentType, artifact.name);
|
|
if (name.endsWith('.zip') || name.endsWith('.tar') || name.endsWith('.gz')) {
|
|
return Icons.folder_zip_outlined;
|
|
}
|
|
if (name.endsWith('.pdf')) {
|
|
return Icons.picture_as_pdf;
|
|
}
|
|
return switch (format) {
|
|
ArtifactPreviewFormat.image => Icons.image_outlined,
|
|
ArtifactPreviewFormat.video => Icons.movie_outlined,
|
|
ArtifactPreviewFormat.audio => Icons.audio_file_outlined,
|
|
ArtifactPreviewFormat.markdown => Icons.article_outlined,
|
|
ArtifactPreviewFormat.text => Icons.description_outlined,
|
|
ArtifactPreviewFormat.table => Icons.table_chart_outlined,
|
|
ArtifactPreviewFormat.html => Icons.html,
|
|
ArtifactPreviewFormat.none => Icons.insert_drive_file_outlined,
|
|
};
|
|
}
|