joseph-grabinger / flutter_to_pdf

Create PDFs but work with normal Flutter Widgets.
MIT License
21 stars 17 forks source link

Error when using a `GlobalKey` inside a `CaptureWrapper` #81

Closed joseph-grabinger closed 3 weeks ago

joseph-grabinger commented 3 months ago

From @Vera-Spoettl in #62:

[✓] Flutter (Channel stable, 3.22.3, on macOS 14.5 23F79 darwin-arm64, locale de-DE) [✓] 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 2023.1) [✓] VS Code (version 1.91.1) [✓] Connected device (4 available) [✓] Network resources

• No issues found!

When I give a GlobalKey to a captured widget, I get the following error during runtime:


════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building CaptureWrapper-[<'someFrame'>]:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 2116 pos 12: '_elements.contains(element)': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub: https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was: CaptureWrapper-[<'someFrame'>] CaptureWrapper:file:///Users/vsz/Development/projects/stuff/report_generator/lib/main.dart:31:15

════════ Exception caught by widgets library ═══════════════════════════════════ Duplicate GlobalKey detected in widget tree. ════════════════════════════════════════════════════════════════════════════════

joseph-grabinger commented 3 months ago

Adjusted the package's example in #82 so we have a common ground to speak about the same example/code-base @Vera-Spoettl.

Vera-Spoettl commented 3 months ago

@joseph-grabinger I'll start to investigate next weekend ...

joseph-grabinger commented 3 weeks ago

Internal Note: A workaround to this issue is to define the GlobalKey inside the CaptureWrapper's scope.