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.47k stars 697 forks source link

syncfusion_flutter_pdfviewer error when setState. #1936

Open SittiphanSittisak opened 1 week ago

SittiphanSittisak commented 1 week ago

Bug description

After the PDF widget is loaded, if the PDF widget was setState the PDF widget will error.

Steps to reproduce

  1. upload PDF files
  2. wait for the SfPdfViewer widgets list to show PDF files.
  3. remove some SfPdfViewer widgets to change the positions of other SfPdfViewer widgets.
  4. use the setState.

Code sample

Code sample ```dart //pubspec.yaml syncfusion_flutter_pdfviewer: ^26.1.38 file_picker: ^8.0.5 //main.dart import 'dart:typed_data'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); 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( 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 { final _scrollController = ScrollController(); final _fileList = []; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Text('github #1936'), Container( height: 100, width: 500, color: Colors.blue, child: Builder( builder: (_) { final children = []; for (final file in _fileList) { final pdfWidget = SfPdfViewer.memory(file.byte); children.add( Container( key: Key(file.name), //This bug happened when using this. If you don't use this, the pdfWidget reloads the pdf file. If you use this, the pdfWidget will not reload(good performance). margin: const EdgeInsets.only(left: 10), constraints: const BoxConstraints(maxWidth: 100, maxHeight: 100), child: AspectRatio( aspectRatio: 1, child: Container( decoration: BoxDecoration(border: Border.all(color: Colors.green)), child: Stack( children: [ Center(child: pdfWidget), Container( alignment: AlignmentDirectional.topEnd, padding: const EdgeInsets.all(8), child: IconButton( icon: const Icon(Icons.delete_forever), onPressed: () async { setState(() => _fileList.remove(file)); }, ), ), ], ), ), ), ), ); } return Scrollbar( controller: _scrollController, thumbVisibility: true, child: ListView( controller: _scrollController, padding: const EdgeInsets.all(8), scrollDirection: Axis.horizontal, children: children, ), ); }, ), ), TextButton( onPressed: () async { final pdf = await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: ['pdf'], allowMultiple: true, ); if (pdf == null) return; for (final item in pdf.files) { _fileList.add(FileModel(name: item.name, byte: item.bytes!)); } setState(() {}); }, child: const Text( 'UPLOAD FILES', style: TextStyle( fontSize: 20, ), ), ) ], ), ), ); } } class FileModel { FileModel({required this.name, required this.byte}); late String name; late Uint8List byte; } ```

Screenshots or Video

Screenshots / Video demonstration https://github.com/syncfusion/flutter-widgets/assets/59549741/0adae137-12e2-4fa6-b5fb-bef44f292fbc

Stack Traces

Stack Traces ```dart ======== Exception caught by widgets library ======================================================= The following TypeErrorImpl was thrown building FutureBuilder>?>(dependencies: [Directionality, MediaQuery, _ViewScope], state: _FutureBuilderState>?>#e7cee): Unexpected null value. When the exception was thrown, this was the stack: dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 297:3 throw_ dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 806:18 nullCheck packages/flutter/src/rendering/sliver_multi_box_adaptor.dart 568:38 childMainAxisPosition packages/flutter/src/rendering/sliver.dart 1803:20 applyPaintTransformForBoxChild packages/flutter/src/rendering/sliver_multi_box_adaptor.dart 597:7 applyPaintTransform packages/flutter/src/rendering/object.dart 3352:22 getTransformTo packages/flutter/src/rendering/box.dart 2619:39 localToGlobal packages/syncfusion_flutter_pdfviewer/src/pdfviewer.dart 2876:48 [_getViewportGlobalRect] packages/syncfusion_flutter_pdfviewer/src/pdfviewer.dart 3053:47 dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 572:46 generate packages/syncfusion_flutter_pdfviewer/src/pdfviewer.dart 3018:53 packages/flutter/src/widgets/async.dart 609:48 build packages/flutter/src/widgets/framework.dart 5592:27 build packages/flutter/src/widgets/framework.dart 5480:15 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5556:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 3973:32 updateChildren packages/flutter/src/widgets/framework.dart 6918:17 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5556:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5556:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5809:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5809:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5556:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/sliver.dart 858:37 updateChild packages/flutter/src/widgets/sliver.dart 759:35 processElement dart-sdk/lib/core/iterable.dart 347:29 forEach packages/flutter/src/widgets/sliver.dart 806:18 performRebuild packages/flutter/src/widgets/sliver.dart 735:7 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 3973:32 updateChildren packages/flutter/src/widgets/framework.dart 6918:17 update packages/flutter/src/widgets/viewport.dart 235:11 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5809:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5809:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5556:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 6765:14 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5809:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5809:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5666:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 5556:5 update packages/flutter/src/widgets/framework.dart 3824:14 updateChild packages/flutter/src/widgets/framework.dart 5505:16 performRebuild packages/flutter/src/widgets/framework.dart 5643:11 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 2904:18 buildScope packages/flutter/src/widgets/binding.dart 989:9 drawFrame packages/flutter/src/rendering/binding.dart 448:5 [_handlePersistentFrameCallback] packages/flutter/src/scheduler/binding.dart 1386:7 [_invokeFrameCallback] packages/flutter/src/scheduler/binding.dart 1311:9 handleDrawFrame packages/flutter/src/scheduler/binding.dart 1169:5 [_handleDrawFrame] lib/_engine/engine/platform_dispatcher.dart 1346:5 invoke lib/_engine/engine/platform_dispatcher.dart 260:5 invokeOnDrawFrame lib/_engine/engine/initialization.dart 185:36 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 550:37 _checkAndCall dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 555:39 dcall ==================================================================================================== ```

On which target platforms have you observed this bug?

Web

Flutter Doctor output

Doctor output ```console Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.19.2, on Microsoft Windows [Version 10.0.19045.4529], locale th-TH) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.6) [√] Android Studio (version 2023.2) [√] VS Code (version unknown) X Unable to determine VS Code version. [√] Connected device (3 available) [√] Network resources • No issues found! ```
immankumarsync commented 1 week ago

Hi @SittiphanSittisak, We are unable to run the code you have shared. Could you please provide the full code? This would help us replicate the exact scenario of the issue.

SittiphanSittisak commented 1 week ago

Hi @immankumarsync, I updated my code.

immankumarsync commented 1 day ago

Hi @SittiphanSittisak, We have checked the reported case with the code you share. But, we are unable to replicate the issue. Please find the video recording below,

https://github.com/syncfusion/flutter-widgets/assets/93641486/9cba6ac3-b264-49f4-9d14-dcf77c250209