split file_viewer into focused sub-widgets

This commit is contained in:
2026-07-13 00:01:07 +02:00
parent 53bc6d5360
commit 2f5a6b4ce0
6 changed files with 512 additions and 479 deletions
@@ -0,0 +1,53 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
import '../app_progress_indicator.dart';
/// SfPdfViewer asserts on `localToGlobal` if mounted during the page-push
/// animation. Defer until the route enter animation completes.
class DeferredPdfViewer extends StatefulWidget {
const DeferredPdfViewer({super.key, required this.path});
final String path;
@override
State<DeferredPdfViewer> createState() => _DeferredPdfViewerState();
}
class _DeferredPdfViewerState extends State<DeferredPdfViewer> {
bool _ready = false;
Animation<double>? _routeAnimation;
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (_ready || _routeAnimation != null) return;
final animation = ModalRoute.of(context)?.animation;
if (animation == null || animation.isCompleted) {
_ready = true;
return;
}
_routeAnimation = animation..addStatusListener(_onAnimationStatus);
}
void _onAnimationStatus(AnimationStatus status) {
if (status == AnimationStatus.completed && mounted) {
setState(() => _ready = true);
}
}
@override
void dispose() {
_routeAnimation?.removeStatusListener(_onAnimationStatus);
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!_ready) {
return const Center(child: AppProgressIndicator.large());
}
return SfPdfViewer.file(File(widget.path));
}
}