endigo / flutter_pdfview

PDF view for Flutter
https://pub.dev/packages/flutter_pdfview
MIT License
261 stars 214 forks source link

[iOS] landscape PDF wrong initial zoom #247

Open enoiu opened 1 year ago

enoiu commented 1 year ago

When viewing a PDF in landscape orientation, the PDF does not fit the screen. When I move to the next page, it fits the screen.

According to this pull, the initial zoom bug on iOS seems to have been resolved, but I think this bug has not been resolved for landscape PDFs.

flutter doctor ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.10.2, on macOS 13.2.1 22D68 darwin-arm64, locale ja-JP) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.1) [✓] VS Code (version 1.78.2) [✓] Connected device (4 available) [✓] Network resources • No issues found! ```
Movie https://github.com/endigo/flutter_pdfview/assets/69666654/ad020df9-f170-44bc-8baf-f518d963b014
Code Example ```dart import 'dart:async'; import 'dart:io'; import 'package:file_picker/file_picker.dart'; import 'package:file_saver/file_saver.dart'; import 'package:flutter/material.dart'; import 'package:flutter_pdfview/flutter_pdfview.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: FilledButton( child: const Text('Open PDF'), onPressed: () async { FilePickerResult? picResult = await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: ['pdf'], ); if (picResult != null) { PlatformFile file = picResult.files.first; String fileName = file.name.replaceAll('.pdf', ''); String savedPath = await FileSaver.instance.saveFile( name: fileName, bytes: File(file.path ?? '').readAsBytesSync(), ext: 'pdf', mimeType: MimeType.pdf, ); if (!mounted) return; Navigator.of(context).push( MaterialPageRoute( builder: (context) => PdfPage(savedPath), ), ); } }, ), ), ); } } class PdfPage extends StatefulWidget { final String path; const PdfPage(this.path, {Key? key}) : super(key: key); @override State createState() => _PdfPageState(); } class _PdfPageState extends State with WidgetsBindingObserver { final Completer _controller = Completer(); int? pages = 0; int? currentPage = 0; bool isReady = false; String errorMessage = ''; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('PDF Page'), ), body: Stack( children: [ PDFView( filePath: widget.path, enableSwipe: true, swipeHorizontal: true, autoSpacing: true, pageFling: true, pageSnap: true, defaultPage: currentPage!, fitPolicy: FitPolicy.BOTH, preventLinkNavigation: false, onRender: (_pages) { setState(() { pages = _pages; isReady = true; }); }, onError: (error) { setState(() { errorMessage = error.toString(); }); print(error.toString()); }, onPageError: (page, error) { setState(() { errorMessage = '$page: ${error.toString()}'; }); print('$page: ${error.toString()}'); }, onViewCreated: (PDFViewController pdfViewController) { _controller.complete(pdfViewController); }, onLinkHandler: (String? uri) { print('goto uri: $uri'); }, onPageChanged: (int? page, int? total) { print('page change: $page/$total'); setState(() { currentPage = page; }); }, ), errorMessage.isEmpty ? !isReady ? const Center( child: CircularProgressIndicator(), ) : Container() : Center( child: Text(errorMessage), ), ], ), ); } } ```
rizkiiansyah commented 1 year ago

Up

JaseElder commented 11 months ago

Same issue for Android