54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
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));
|
|
}
|
|
}
|