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.57k stars 764 forks source link

SfPdfViewer: "'PdfName' is not a subtype of type 'PdfDictionary?'" on mouseover #2113

Open idonthavetimeforthis opened 1 day ago

idonthavetimeforthis commented 1 day ago

Bug description

SfPdfViewer will throw the exception "type 'PdfName' is not a subtype of type 'PdfDictionary?' in type cast" when hovering the viewer with the mouse on specifics PDF.

syncfusion_flutter_pdf: ^27.1.51 syncfusion_flutter_pdfviewer: ^27.1.51

Steps to reproduce

  1. Open the PDF through: "SfPdfViewer.memory" or "SfPdfViewer.file"
  2. Hover the mouse over the viewer

See reproductive repository.

Code sample

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:syncfusion_flutter_pdf/pdf.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        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});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Uint8List? _pdfData;

  @override
  void initState() {
    super.initState();
  _loadPDF();
  }

  Future<void> _loadPDF() async {
    final ByteData data = await rootBundle.load('assets/S355J2+N EP30 - 324521 - 2346991068.pdf');
    setState(() {
      _pdfData = data.buffer.asUint8List();
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: _pdfData != null ? Center(child: SfPdfViewer.memory(_pdfData!)) : Center(child: CircularProgressIndicator()),
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
    );
  }
}

Screenshots or Video

No.

Stack Traces

Stack Traces ```dart ======== Exception caught by gesture library ======================================================= The following _TypeError was thrown while dispatching a pointer event: type 'PdfName' is not a subtype of type 'PdfDictionary?' in type cast When the exception was thrown, this was the stack: #0 FontStructure.getFontEncoding (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/font_structure.dart:1106:23) #1 FontStructure.fontEncoding (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/font_structure.dart:183:49) #2 FontStructure.decodeTextExtraction (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/font_structure.dart:2612:9) #3 ImageRenderer._renderTextElementWithLeading (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/image_renderer.dart:642:26) #4 ImageRenderer.renderAsImage (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/image_renderer.dart:386:17) #5 PdfTextExtractor._getTextLine (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart:346:14) #6 PdfTextExtractor._extractTextLines (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart:212:14) #7 PdfTextExtractor.extractTextLines (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart:131:12) #8 CanvasRenderBox.findTextWhileHover (package:syncfusion_flutter_pdfviewer/src/control/pdfviewer_canvas.dart:1743:12) #9 PdfPageViewState.build.. (package:syncfusion_flutter_pdfviewer/src/control/pdf_page_view.dart:637:38) #10 State.setState (package:flutter/src/widgets/framework.dart:1203:30) #11 PdfPageViewState.build. (package:syncfusion_flutter_pdfviewer/src/control/pdf_page_view.dart:629:23) #12 RenderMouseRegion.handleEvent (package:flutter/src/rendering/proxy_box.dart:3170:22) #13 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:481:22) #14 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:450:11) #15 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:426:7) #16 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:389:5) #17 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:336:7) #18 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:305:9) #19 _invoke1 (dart:ui/hooks.dart:328:13) #20 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:442:7) #21 _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31) Event: PointerHoverEvent#c96ee(position: Offset(1259.0, 553.0)) position: Offset(1259.0, 553.0) Target: RenderMouseRegion#3fbd6 relayoutBoundary=up5 parentData: (can use size) constraints: BoxConstraints(0.0<=w<=1264.0, 0.0<=h<=Infinity) size: Size(1264.0, 893.2) behavior: opaque listeners: hover cursor: SystemMouseCursor(basic) ==================================================================================================== ```

On which target platforms have you observed this bug?

Windows

Flutter Doctor output

[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [version 10.0.22631.4169], locale fr-FR) • Flutter version 3.24.3 on channel stable at C:\tools\flutter_windows_3.22.3-stable\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 2663184aa7 (4 weeks ago), 2024-09-11 16:27:48 -0500 • Engine revision 36335019a8 • Dart version 3.5.3 • DevTools version 2.37.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0) • Android SDK at C:\Users\robin\AppData\Local\Android\sdk • Platform android-35, build-tools 35.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.6) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.9.34728.123 • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.1) • Android Studio at C:\Program Files\Android\Android Studio • 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.11+0--11852314)

[√] IntelliJ IDEA Ultimate Edition (version 2024.2) • IntelliJ at C:\Users\robin\AppData\Local\Programs\IntelliJ IDEA Ultimate • Flutter plugin version 81.1.3 • Dart plugin version 242.20629

[√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [version 10.0.22631.4169] • Chrome (web) • chrome • web-javascript • Google Chrome 129.0.6668.90 • Edge (web) • edge • web-javascript • Microsoft Edge 129.0.2792.65

[√] Network resources • All expected network resources are available.

• No issues found!

immankumarsync commented 7 hours ago

Hi, We are able to replicate the issue with the shared document. Currently we are validating the issue, and we will update once we found the cause of the issue.