syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.44k stars 672 forks source link

PDF Viewer in iOS App Causes Crash #1840

Open mehdico opened 2 weeks ago

mehdico commented 2 weeks ago

Bug description

When attempting to open attached PDF, the iOS app crashes after a few seconds.

Steps to reproduce

Open attached pdf

pdf causing crash.pdf

Code sample

Code sample ```dart SfPdfViewer.network( url, controller: _pdfViewerController, onDocumentLoaded: (details) => { WidgetsBinding.instance .addPostFrameCallback( (_) => setState(() { ... }), ), }, onDocumentLoadFailed: (details) => { WidgetsBinding.instance .addPostFrameCallback( (_) => setState(() { ... }), ), }, canShowScrollHead: true, canShowScrollStatus: true, canShowPaginationDialog: false, ) ```

Screenshots or Video

Screenshots / Video demonstration

Stack Traces

Stack Traces ``` syncfusion_flutter_pdfviewer/SwiftSyncfusionFlutterPdfViewerPlugin.swift:128: Fatal error: Unexpectedly found nil while unwrapping an Optional value syncfusion_flutter_pdfviewer/SwiftSyncfusionFlutterPdfViewerPlugin.swift:128: Fatal error: Unexpectedly found nil while unwrapping an Optional value * thread #56, queue = 'syncfusion_flutter_pdfviewer', stop reason = Fatal error: Unexpectedly found nil while unwrapping an Optional value frame #0: 0x0000000184e51ebc libswiftCore.dylib`_swift_runtime_on_report ```

On which target platforms have you observed this bug?

iOS

Flutter Doctor output

Doctor output ``` [✓] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale en-US) • Flutter version 3.19.5 on channel stable at /Users/mehdi/devtools/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 300451adae (5 weeks ago), 2024-03-27 21:54:07 -0500 • Engine revision e76c956498 • Dart version 3.3.3 • DevTools version 2.31.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/mehdi/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) [✓] VS Code (version 1.88.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (3 available) • Mehdi’s iPhone (mobile) • 4aca82c576738288682dd582ea5557ddf7732625 • ios • iOS 15.8.2 19H384 • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.93 [✓] Network resources • All expected network resources are available. • No issues found! ```
immankumarsync commented 2 weeks ago

Hi @mehdico, We are unable to replicate the issue, and we suspect this is a document-specific issue. Could you please share the following information, which will help us analyze the issue further?

mehdico commented 1 week ago

Hi @immankumarsync, I have updated the issue with a sample pdf which is causing the crash. I've also added a sample code.

mahdinba97 commented 1 week ago

Same thing happens for me. @immankumarsync While running the following code sample, If we tap on the 'Open Page' button and wait for the PDF to load, wait for a few seconds after, then close the screen, and press 'Open Page' again. The app will crash.

Note: Crash happens only for some types of PDF files, which one of them is uploaded to a public file storage and the URL exists in the following sample code.

https://github.com/syncfusion/flutter-widgets/assets/29746159/b5f3930c-5801-4a6b-b8c0-549af825991b

Code sample:

// main.dart
import 'package:flutter/material.dart';
import 'pdf_page.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'PDF Viewer Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const HomePage(title: 'PDF Viewer Example'),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key, required this.title});
  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(title),
      ),
      body: Center(
        child: ElevatedButton(
          child: Text('Open PDF'),
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => const PdfPage(),
              ),
            );
          },
        ),
      ),
    );
  }
}
// pdf_page.dart
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';

class PdfPage extends StatefulWidget {
  const PdfPage({super.key});
  @override
  State<PdfPage> createState() => _PdfPageState();
}

class _PdfPageState extends State<PdfPage> {
  final PdfViewerController _pdfViewerController = PdfViewerController();

  @override
  void dispose() {
    super.dispose();
    _pdfViewerController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('Sample PDF'),
      ),
      body: Center(
        child: SfPdfViewer.network(
          'https://filebin.net/oh0140hws3osvtsl/pdf_causing_crash.pdf',
          controller: _pdfViewerController,
          canShowScrollHead: true,
          canShowScrollStatus: true,
          canShowPaginationDialog: false,
        ),
      ),
    );
  }
}
immankumarsync commented 1 week ago

Hi @mehdico, now we are able to replicate the issue that the application crashes with specific PDF document. Currently, we are validating the issue, and we will update further details here once the root cause for this issue is found.

mahdinba97 commented 1 week ago

Hi @immankumarsync. Any updates on this problem? By the way could you please remove "waiting for customer response" tag, so the dev team (including yourself) would not miss it alongside the current active bugs?

Abolfazlnezami2000 commented 6 days ago

I have the same issue. Do you have any updates for this bug? @immankumarsync

Ali-Azmoud commented 6 days ago

Hi, Same here. I encountered this bug about a month ago, I created a PDF using the acrobat creator plugin on Microsoft Word, and while opening it in the app, the app crashes after some seconds. any update? @VijayakumarMariappan @ramkumarsync

immankumarsync commented 4 days ago

We have confirmed that the issue “Application crashes when loading a specific document in iOS platform” is a defect and logged a defect report for this issue. The fix for the same will be included in the 2024 May 28th weekly release.