Media viewer details panel, Upload FAB size setting, PDF zoom/viewport fixes, avatar menu account switcher; bump to 1.0.2+5
Build App Bundle / build (push) Successful in 6m2s
Build App Bundle / build (push) Successful in 6m2s
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -22,9 +22,14 @@ class MediaActionBar extends StatelessWidget {
|
||||
final VoidCallback onDelete;
|
||||
final VoidCallback onOpenExternally;
|
||||
final VoidCallback onDownload;
|
||||
final VoidCallback onDetails;
|
||||
final VoidCallback? onDetails;
|
||||
final Widget? handle;
|
||||
final Widget? below;
|
||||
|
||||
const MediaActionBar({
|
||||
this.onDetails,
|
||||
this.handle,
|
||||
this.below,
|
||||
super.key,
|
||||
required this.isFavorite,
|
||||
required this.isBusy,
|
||||
@@ -35,7 +40,6 @@ class MediaActionBar extends StatelessWidget {
|
||||
required this.onDelete,
|
||||
required this.onOpenExternally,
|
||||
required this.onDownload,
|
||||
required this.onDetails,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -48,11 +52,15 @@ class MediaActionBar extends StatelessWidget {
|
||||
// short and leaving that strip unstyled - only the actual row content
|
||||
// needs padding up and away from the gesture area.
|
||||
return FrostedGlassContainer(
|
||||
radius: const BorderRadius.vertical(
|
||||
top: Radius.circular(NooRadii.sheetTop),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
?handle,
|
||||
if (transportControls != null) ...[
|
||||
transportControls!,
|
||||
Divider(height: 1, color: colors.fg1.withValues(alpha: 0.14)),
|
||||
@@ -94,17 +102,18 @@ class MediaActionBar extends StatelessWidget {
|
||||
ViewerIconButton(
|
||||
icon: LucideIcons.trash2,
|
||||
tooltip: 'Delete',
|
||||
color: colors.danger,
|
||||
onTap: isBusy ? null : onDelete,
|
||||
),
|
||||
ViewerIconButton(
|
||||
icon: LucideIcons.info,
|
||||
tooltip: 'Details',
|
||||
onTap: onDetails,
|
||||
),
|
||||
if (onDetails != null)
|
||||
ViewerIconButton(
|
||||
icon: LucideIcons.info,
|
||||
tooltip: 'Details',
|
||||
onTap: onDetails,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
?below,
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../models/nextcloud_item.dart';
|
||||
import '../../theme/design_tokens.dart';
|
||||
import '../details/details_sheet.dart';
|
||||
import '../noo/overlays/noo_overlay_header.dart';
|
||||
|
||||
/// Builds the viewer's bottom bar with a drag [handle] on top and the
|
||||
/// expandable [below] details region underneath its action row.
|
||||
typedef MediaPanelBarBuilder =
|
||||
Widget Function(BuildContext context, Widget handle, Widget below);
|
||||
|
||||
/// The media viewer's bottom bar as a draggable panel: dragging it (or
|
||||
/// swiping up on the media, via [MediaDetailsPanelState.expand]) grows the
|
||||
/// panel upward so the action row rides on top of the file's details instead
|
||||
/// of the details covering it in a separate modal sheet.
|
||||
class MediaDetailsPanel extends StatefulWidget {
|
||||
final NextcloudItem item;
|
||||
final MediaPanelBarBuilder builder;
|
||||
|
||||
const MediaDetailsPanel({
|
||||
super.key,
|
||||
required this.item,
|
||||
required this.builder,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MediaDetailsPanel> createState() => MediaDetailsPanelState();
|
||||
}
|
||||
|
||||
class MediaDetailsPanelState extends State<MediaDetailsPanel>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _c = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 260),
|
||||
);
|
||||
double _maxHeight = 1;
|
||||
|
||||
bool get isExpanded => _c.value > 0.5;
|
||||
|
||||
void expand() => _c.animateTo(1, curve: Curves.easeOutCubic);
|
||||
void collapse() => _c.animateTo(0, curve: Curves.easeOutCubic);
|
||||
void toggle() => isExpanded ? collapse() : expand();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_c.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onDragUpdate(DragUpdateDetails d) {
|
||||
_c.value -= (d.primaryDelta ?? 0) / _maxHeight;
|
||||
}
|
||||
|
||||
void _onDragEnd(DragEndDetails d) {
|
||||
final v = d.primaryVelocity ?? 0;
|
||||
if (v < -400) {
|
||||
expand();
|
||||
} else if (v > 400) {
|
||||
collapse();
|
||||
} else {
|
||||
toggleToNearest();
|
||||
}
|
||||
}
|
||||
|
||||
void toggleToNearest() => _c.value > 0.5 ? expand() : collapse();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.nooColors;
|
||||
_maxHeight = MediaQuery.sizeOf(context).height * 0.55;
|
||||
|
||||
final handle = Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 2),
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.fg3.withValues(alpha: 0.6),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final below = AnimatedBuilder(
|
||||
animation: _c,
|
||||
builder: (context, _) {
|
||||
if (_c.value == 0) return const SizedBox.shrink();
|
||||
return SizedBox(
|
||||
height: _c.value * _maxHeight,
|
||||
child: ClipRect(
|
||||
child: OverflowBox(
|
||||
alignment: Alignment.topCenter,
|
||||
minHeight: 0,
|
||||
maxHeight: _maxHeight,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
NooSpace.lg,
|
||||
NooSpace.md,
|
||||
NooSpace.lg,
|
||||
NooSpace.lg,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
NooOverlayHeader(
|
||||
leading: detailsFileTile(widget.item),
|
||||
title: widget.item.name,
|
||||
subtitle: detailsMetaLine(widget.item),
|
||||
onClose: collapse,
|
||||
),
|
||||
const SizedBox(height: NooSpace.lg),
|
||||
DetailsBody(
|
||||
key: ValueKey(widget.item.id),
|
||||
item: widget.item,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return GestureDetector(
|
||||
onVerticalDragUpdate: _onDragUpdate,
|
||||
onVerticalDragEnd: _onDragEnd,
|
||||
child: widget.builder(context, handle, below),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,12 @@ class MediaPdfPreview extends StatefulWidget {
|
||||
/// `FileViewerScreen.localPathResolver`'s doc comment.
|
||||
final Future<String?> Function(NextcloudItem item)? localPathResolver;
|
||||
|
||||
/// Space reserved above the page for an overlaid top bar (0 when hidden).
|
||||
final double topInset;
|
||||
|
||||
const MediaPdfPreview({
|
||||
super.key,
|
||||
this.topInset = 0,
|
||||
required this.item,
|
||||
required this.session,
|
||||
this.localPathResolver,
|
||||
@@ -29,8 +33,14 @@ class MediaPdfPreview extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MediaPdfPreviewState extends State<MediaPdfPreview> {
|
||||
// Only the first few pages are measured; longer documents are assumed
|
||||
// taller than any screen.
|
||||
static const _sizedPages = 3;
|
||||
|
||||
PdfControllerPinch? _controller;
|
||||
String? _error;
|
||||
List<Size> _pageSizes = const [];
|
||||
int _pageCount = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -55,9 +65,21 @@ class _MediaPdfPreviewState extends State<MediaPdfPreview> {
|
||||
await widget.session.service!.fetchBytes(widget.item.path),
|
||||
);
|
||||
}
|
||||
if (!mounted) return;
|
||||
final document = await PdfDocument.openData(bytes);
|
||||
final sizes = <Size>[];
|
||||
for (var i = 1; i <= document.pagesCount && i <= _sizedPages; i++) {
|
||||
// autoCloseAndroid closes the previous page itself; closing here too throws.
|
||||
final page = await document.getPage(i, autoCloseAndroid: true);
|
||||
sizes.add(Size(page.width, page.height));
|
||||
}
|
||||
if (!mounted) {
|
||||
await document.close();
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_controller = PdfControllerPinch(document: PdfDocument.openData(bytes));
|
||||
_pageSizes = sizes;
|
||||
_pageCount = document.pagesCount;
|
||||
_controller = PdfControllerPinch(document: Future.value(document));
|
||||
});
|
||||
} catch (e) {
|
||||
if (mounted) setState(() => _error = e.toString());
|
||||
@@ -91,6 +113,44 @@ class _MediaPdfPreviewState extends State<MediaPdfPreview> {
|
||||
// without ever pinching to zoom. There's no way to override that
|
||||
// margin from here - it isn't an exposed parameter - so this avoids
|
||||
// the branch that sets it instead of fighting it.
|
||||
return PdfViewPinch(controller: _controller!);
|
||||
//
|
||||
// pdfx's InteractiveViewer also refuses to zoom out past
|
||||
// `viewport.height / document.height`. When the whole document is
|
||||
// shorter than the screen (e.g. a one-page PDF) that ratio is above 1, so
|
||||
// after pinching in, fit-width (scale 1) becomes unreachable. PdfViewPinch
|
||||
// wraps its content in a SafeArea, which counts MediaQuery padding toward
|
||||
// that document height, so padding the bottom up to the viewport height
|
||||
// keeps the ratio at or below 1 without shrinking the gesture area.
|
||||
return AnimatedPadding(
|
||||
duration: const Duration(milliseconds: 220),
|
||||
curve: Curves.easeInOutCubic,
|
||||
padding: EdgeInsets.only(top: widget.topInset),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final media = MediaQuery.of(context);
|
||||
var padding = media.padding.copyWith(top: 0);
|
||||
if (_pageSizes.isNotEmpty && _pageSizes.length == _pageCount) {
|
||||
const pagePadding = 10.0; // PdfViewPinch's default `padding`
|
||||
final maxWidth = _pageSizes.fold<double>(
|
||||
0,
|
||||
(m, s) => s.width > m ? s.width : m,
|
||||
);
|
||||
final ratio = (constraints.maxWidth - pagePadding * 2) / maxWidth;
|
||||
final docHeight = _pageSizes.fold<double>(
|
||||
pagePadding,
|
||||
(h, s) => h + s.height * ratio + pagePadding,
|
||||
);
|
||||
final needed = constraints.maxHeight - docHeight;
|
||||
if (needed > padding.bottom) {
|
||||
padding = padding.copyWith(bottom: needed);
|
||||
}
|
||||
}
|
||||
return MediaQuery(
|
||||
data: media.copyWith(padding: padding),
|
||||
child: PdfViewPinch(controller: _controller!),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user