- Notifications
You must be signed in to change notification settings - Fork 898
Open
Labels
bugSomething isn't workingSomething isn't workingfollow-up scheduledFollow-up scheduledFollow-up scheduledpdf viewerPDF viewer componentPDF viewer component
Description
Bug description
The syncfusion_flutter_pdfviewer on the web platform is not gracefully handling the 404 error. Instead of just reporting it via onDocumentLoadFailed, it's also letting an unhandled ClientException escape, which can disrupt the app's state.
Steps to reproduce
- pass any url to the screen so it will produce 404
- run on web (chrome)
- get the error
Code sample
Code sample
// lib/screens/pdf_viewer_screen.dart import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; class PdfViewerScreenArgs { PdfViewerScreenArgs({required this.pdfUrl, required this.documentName}); final String documentName; final String pdfUrl; } enum PdfLoadingState { loading, success, error } class PdfViewerScreen extends StatefulWidget { const PdfViewerScreen({super.key, required this.pdfUrl, required this.documentName}); final String documentName; final String pdfUrl; @override State<PdfViewerScreen> createState() => _PdfViewerScreenState(); } class _PdfViewerScreenState extends State<PdfViewerScreen> { String _errorMessage = ''; PdfLoadingState _loadingState = PdfLoadingState.loading; Widget _buildLoadingWidget() { return const ColoredBox( color: Colors.white, child: Center(child: CircularProgressIndicator()), ); } Widget _buildErrorWidget(String message) { return ColoredBox( color: Colors.white, child: Center( child: Padding( padding: const EdgeInsets.all(24.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.cloud_off_rounded, color: Colors.grey.shade500, size: 60), const SizedBox(height: 16), Text('Failed to Load Document', textAlign: TextAlign.center, style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 8), Text( message, textAlign: TextAlign.center, style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey.shade700), ), ], ), ), ), ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(widget.documentName), backgroundColor: const Color(0xFFF2F8F2)), body: Stack( children: [ SfPdfViewer.network( widget.pdfUrl, key: Key(widget.pdfUrl), onDocumentLoaded: (details) { if (mounted) { setState(() { _loadingState = PdfLoadingState.success; }); } }, onDocumentLoadFailed: (details) { log('PDF Load Failed: ${details.error} - ${details.description}'); if (mounted) { setState(() { _loadingState = PdfLoadingState.error; _errorMessage = 'Document not found or failed to load.'; }); } }, ), if (_loadingState == PdfLoadingState.loading) _buildLoadingWidget(), if (_loadingState == PdfLoadingState.error) _buildErrorWidget(_errorMessage), ], ), ); } }
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Stack Traces
Stack Traces
[log] PDF Load Failed: Error - There was an error opening this document. DartError: ClientException: Request to https://dashboard-owwy.wijayalab.uk/api/documents/9/agreement_v1.pdf failed with status 404: ., uri=https://dashboard-owwy.wijayalab.uk/api/documents/9/agreement_v1.pdf dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 274:3 throw_ errors.dart:274 package:http/src/base_client.dart 103:5 [_checkResponseSuccess] base_client.dart:103 package:http/src/base_client.dart 59:5 <fn> base_client.dart:59 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 623:19 <fn> async_patch.dart:623 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 648:23 <fn> async_patch.dart:648 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 594:19 <fn> async_patch.dart:594 dart-sdk/lib/async/zone.dart 1849:54 runUnary zone.dart:1849 dart-sdk/lib/async/future_impl.dart 222:18 handleValue future_impl.dart:222 dart-sdk/lib/async/future_impl.dart 948:44 handleValueCallback future_impl.dart:948 dart-sdk/lib/async/future_impl.dart 977:13 _propagateToListeners future_impl.dart:977 dart-sdk/lib/async/future_impl.dart 720:5 [_completeWithValue] future_impl.dart:720 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 504:7 complete async_patch.dart:504 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 571:12 _asyncReturn async_patch.dart:571 package:http/src/response.dart 66:3 <fn> response.dart:66 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 623:19 <fn> async_patch.dart:623 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 648:23 <fn> async_patch.dart:648 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 594:19 <fn> async_patch.dart:594 dart-sdk/lib/async/zone.dart 1849:54 runUnary zone.dart:1849 dart-sdk/lib/async/future_impl.dart 222:18 handleValue future_impl.dart:222 dart-sdk/lib/async/future_impl.dart 948:44 handleValueCallback future_impl.dart:948 dart-sdk/lib/async/future_impl.dart 977:13 _propagateToListeners future_impl.dart:977 dart-sdk/lib/async/future_impl.dart 720:5 [_completeWithValue] future_impl.dart:720 dart-sdk/lib/async/future_impl.dart 804:7 <fn> future_impl.dart:804 dart-sdk/lib/async/schedule_microtask.dart 40:34 _microtaskLoop schedule_microtask.dart:40 dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop schedule_microtask.dart:49 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 118:77 tear operations.dart:118 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 188:69 <fn> async_patch.dart:188 DartError: ClientException: Request to https://dashboard-owwy.wijayalab.uk/api/documents/9/agreement_v1.pdf failed with status 404: ., uri=https://dashboard-owwy.wijayalab.uk/api/documents/9/agreement_v1.pdf dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 274:3 throw_ errors.dart:274 package:http/src/base_client.dart 103:5 [_checkResponseSuccess] base_client.dart:103 package:http/src/base_client.dart 59:5 <fn> base_client.dart:59 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 623:19 <fn> async_patch.dart:623 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 648:23 <fn> async_patch.dart:648 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 594:19 <fn> async_patch.dart:594 dart-sdk/lib/async/zone.dart 1849:54 runUnary zone.dart:1849 dart-sdk/lib/async/future_impl.dart 222:18 handleValue future_impl.dart:222 dart-sdk/lib/async/future_impl.dart 948:44 handleValueCallback future_impl.dart:948 dart-sdk/lib/async/future_impl.dart 977:13 _propagateToListeners future_impl.dart:977 dart-sdk/lib/async/future_impl.dart 720:5 [_completeWithValue] future_impl.dart:720 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 504:7 complete async_patch.dart:504 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 571:12 _asyncReturn async_patch.dart:571 package:http/src/response.dart 66:3 <fn> response.dart:66 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 623:19 <fn> async_patch.dart:623 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 648:23 <fn> async_patch.dart:648 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 594:19 <fn> async_patch.dart:594 dart-sdk/lib/async/zone.dart 1849:54 runUnary zone.dart:1849 dart-sdk/lib/async/future_impl.dart 222:18 handleValue future_impl.dart:222 dart-sdk/lib/async/future_impl.dart 948:44 handleValueCallback future_impl.dart:948 dart-sdk/lib/async/future_impl.dart 977:13 _propagateToListeners future_impl.dart:977 dart-sdk/lib/async/future_impl.dart 720:5 [_completeWithValue] future_impl.dart:720 dart-sdk/lib/async/future_impl.dart 804:7 <fn> future_impl.dart:804 dart-sdk/lib/async/schedule_microtask.dart 40:34 _microtaskLoop schedule_microtask.dart:40 dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop schedule_microtask.dart:49 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 118:77 tear operations.dart:118 dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 188:69 <fn> async_patch.dart:188
On which target platforms have you observed this bug?
Web
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.35.4, on Microsoft Windows [Version 10.0.26120.4520], locale en-ID) [411ms] • Flutter version 3.35.4 on channel stable at C:\bin\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision d693b4b9db (3 weeks ago), 2025-09-16 14:27:41 +0000 • Engine revision c298091351 • Dart version 3.9.2 • DevTools version 2.48.0 • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-lldb-debugging [✓] Windows Version (11 Pro 64-bit, 24H2, 2009) [2.7s] [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [2.6s] • Android SDK at C:\android\sdk • Emulator version 35.4.9.0 (build_id 13025442) (CL:N/A) • Platform android-35, build-tools 35.0.1 • ANDROID_HOME = C:\android\sdk • ANDROID_SDK_ROOT = C:\android\sdk • Java binary at: C:\Program Files\Microsoft\jdk-17.0.15.6-hotspot\bin\java This JDK is specified in your Flutter configuration. To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`. • Java version OpenJDK Runtime Environment Microsoft-11369865 (build 17.0.15+6-LTS) • All Android licenses accepted. [✓] Chrome - develop for the web [158ms] • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.14.5) [157ms] • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.14.36203.30 • Windows 10 SDK version 10.0.26100.0 [✓] Android Studio (version 2024.3) [52ms] • 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 21.0.5+-12932927-b750.29) [✓] IntelliJ IDEA Ultimate Edition (version 2024.2) [50ms] • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2024.2.3 • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin version 242.22855.32 [✓] VS Code (version 1.105.0) [7ms] • VS Code at C:\Users\Rizki Aprita\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.120.0 [✓] Connected device (3 available) [172ms] • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26120.4520] • Chrome (web) • chrome • web-javascript • Google Chrome 140.0.7339.210 • Edge (web) • edge • web-javascript • Microsoft Edge 140.0.3485.14 [✓] Network resources [1,326ms] • All expected network resources are available. • No issues found!
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfollow-up scheduledFollow-up scheduledFollow-up scheduledpdf viewerPDF viewer componentPDF viewer component