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.6k stars 788 forks source link

syncfusion_flutter_pdfviewer - Null check operator used on a null value #2021

Closed FetFrumos closed 3 months ago

FetFrumos commented 3 months ago

Bug description

I used syncfusion_flutter_pdfviewer 26.2.7 in my Flutter(3.22) app. This is my code:

 ```

return SfPdfViewer.file(file, pageSpacing: pageSpacing, pageLayoutMode: pageLayoutMode, canShowScrollStatus: canShowScrollStatus, canShowScrollHead: canShowScrollHead, enableTextSelection: enableTextSelection, enableDoubleTapZooming: enableDoubleTapZooming, onTap: (details) {

  });

I got error - "Null check operator used on a null value"(more detail in "Stack Trace").  The app works but I see this error in the console - it also shows up in Firebase Crashlytics. This error only for Android, not for iOS

Also I tried it in syncfusion_flutter_pdfviewer  26.2.8 with  Flutter(3.24) - same error. 

But this error is absent if I use :

  `syncfusion_flutter_pdfviewer: 26.1.40`

### Steps to reproduce

1. Using syncfusion_flutter_pdfviewer older than 26.1.40.
2. Run flutter app on android.
3. Try open file from file system
4. Got error in debug console - "Null check operator used on a null value"

### Code sample

<details open><summary>Code sample</summary>

```dart
return SfPdfViewer.file(file,
          pageSpacing: pageSpacing,
          pageLayoutMode: pageLayoutMode,
          canShowScrollStatus: canShowScrollStatus,
          canShowScrollHead: canShowScrollHead,
          enableTextSelection: enableTextSelection,
          enableDoubleTapZooming: enableDoubleTapZooming, 
          onTap: (details) {

      });

Screenshots or Video

Screenshots / Video demonstration ![image](https://github.com/user-attachments/assets/8bbf21b2-0c4e-4ebd-9ac3-a6c7b5f33402)

Stack Traces

Stack Traces Null check operator used on a null value The relevant error-causing widget was: ```dart When the exception was thrown, this was the stack: #0 SinglePageViewState.build. (package:syncfusion_flutter_pdfviewer/src/control/single_page_view.dart:584:69) #1 _LayoutBuilderElement._layout.layoutCallback (package:flutter/src/widgets/layout_builder.dart:139:77) #2 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2845:19) #3 _LayoutBuilderElement._layout (package:flutter/src/widgets/layout_builder.dart:173:12) #4 RenderObject.invokeLayoutCallback. (package:flutter/src/rendering/object.dart:2688:59) #5 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:1097:15) #6 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:2688:14) #7 RenderConstrainedLayoutBuilder.rebuildIfNecessary (package:flutter/src/widgets/layout_builder.dart:248:7) #8 _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:331:5) #9 RenderObject.layout (package:flutter/src/rendering/object.dart:2577:7) #10 ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:52:11) #11 RenderStack._computeSize (package:flutter/src/rendering/stack.dart:574:43) #12 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:601:12) #13 RenderObject.layout (package:flutter/src/rendering/object.dart:2577:7) #14 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:21) #15 RenderObject.layout (package:flutter/src/rendering/object.dart:2577:7) #16 ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:52:11) #17 RenderStack._computeSize (package:flutter/src/rendering/stack.dart:574:43) #18 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:601:12) #19 RenderObject.layout (package:flutter/src/rendering/object.dart:2577:7) #20 _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:333:14) #21 RenderObject.layout (package:flutter/src/rendering/object.dart:2577:7) #22 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:21) #23 RenderObject.layout (package:flutter/src/rendering/object.dart:2577:7) #24 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:21) #25 RenderObject.layout (package:flutter/src/rendering/object.dart:2577:7) #26 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:21) #27 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2416:7) #28 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1051:18) #29 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1064:15) #30 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:577:23) #31 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1138:13) #32 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:443:5) #33 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15) #34 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1313:9) #35 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1171:5) #36 _invoke (dart:ui/hooks.dart:312:13) #37 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5) #38 _drawFrame (dart:ui/hooks.dart:283:31) ```

On which target platforms have you observed this bug?

Android

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel stable, 3.22.3, on macOS 14.6.1 23G93 darwin-arm64, locale en-UA) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.4) [✓] Chrome - develop for the web [✓] Android Studio (version 2024.1) [✓] VS Code (version 1.92.1) [✓] Connected device (4 available) [✓] Network resources • No issues found! ```
immankumarsync commented 3 months ago

Hi @FetFrumos, We are unable to replicate the reported issue. Please check the video recording of the issue replication and let us know what we are missing in replicating the video.

https://github.com/user-attachments/assets/41c46404-3ab0-497c-a364-3690259478b4

dependencies:
  flutter:
    sdk: flutter
  syncfusion_flutter_pdfviewer: '26.1.39'
  path_provider:
  file_picker:
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: PDFViewerPage(),
    );
  }
}

class PDFViewerPage extends StatefulWidget {
  const PDFViewerPage({super.key});

  @override
  State<PDFViewerPage> createState() => _PDFViewerPageState();
}

class _PDFViewerPageState extends State<PDFViewerPage> {
  File? _file;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: [
          IconButton(
            onPressed: _open,
            icon: const Icon(Icons.folder),
          ),
        ],
      ),
      body: _file != null
          ? SfPdfViewer.file(
              _file!,
              pageLayoutMode: PdfPageLayoutMode.single,
              pageSpacing: 20,
              canShowScrollStatus: false,
              canShowScrollHead: false,
              enableTextSelection: false,
              enableDoubleTapZooming: false,
              onTap: (details) {
                print('Page number: ${details.pageNumber}');
              },
            )
          : const Center(child: CircularProgressIndicator()),
    );
  }

  Future<void> _open() async {
    final result = await FilePicker.platform.pickFiles(
      type: FileType.custom,
      allowedExtensions: ['pdf'],
    );
    if (result != null) {
      final path = result.files.single.path!;

      setState(() {
        _file = File(path);
      });
    }
  }
}
FetFrumos commented 3 months ago

@immankumarsync Please, please check the versions that are older 26.1.40. I checked with 26.2.7 and 26.2.8. These versions have issue "Null check operator used on a null value"

immankumarsync commented 3 months ago

@FetFrumos, we are able to replicate the reported issue rarely when switching the documents faster. We will fix the issue based on the provided stack trace. This will be included in our August 20,2024 weekly release.

immankumarsync commented 3 months ago

@FetFrumos, we have resolved the issue based on the stack trace and fix is available in our latest weekly release. Package link: syncfusion_flutter_pdfviewer v26.2.10

Kindly let us know whether the issue is resolved on your end.

FetFrumos commented 3 months ago

@immankumarsync - it is fixed, thanks.