packages.flutter icon indicating copy to clipboard operation
packages.flutter copied to clipboard

Using pdfView with flutter 2.10.1 causes an error "Looking up a deactivated widget's ancestor is unsafe."

Open bdairy opened this issue 2 years ago • 5 comments

Once you navigate out of the view you see this error..

using pdfx: ^2.0.1+1. and flutter 2.10.1

it was working fine before flutter upgrade.. here is my widget code..

PhotoViewGalleryPageOptions _pageBuilder(
          BuildContext context,
          Future<PdfPageImage> pageImage,
          int index,
          PdfDocument document,
        ) =>
            PhotoViewGalleryPageOptions(
              imageProvider: PdfPageImageProvider(
                pageImage,
                index,
                document.id,
              ),
              minScale: PhotoViewComputedScale.contained * 1,
              maxScale: PhotoViewComputedScale.contained * model.getMaxScale(),
              initialScale: PhotoViewComputedScale.contained * 1.0,
              heroAttributes:
                  PhotoViewHeroAttributes(tag: '${document.id}-$index'),
            );

// here is the pdf view

 PdfView(
                backgroundDecoration: const BoxDecoration(color: Colors.black),
                controller: model.pdfController!,
                renderer: (page) {
                  model.setPageSize(
                      page.height.toDouble(),
                      page.width.toDouble(),
                      MediaQuery.of(context).size,
                      Scaffold.of(context).appBarMaxHeight!.toDouble());

                  return page.render(
                    backgroundColor: '#FFFFFF',
                    width: page.width * 2,
                    height: page.height * 2,
                  );
                },
                onDocumentLoaded: (document) {
                  model.setLoaded(document);
                },
                onPageChanged: (page) {
                  model.setPageIndex(page);
                },
                builders: PdfViewBuilders<DefaultBuilderOptions>(
                  // All from `PdfViewPinch` and:
                  pageBuilder: _pageBuilder,
                  options: const DefaultBuilderOptions(
                    loaderSwitchDuration: const Duration(seconds: 1),
                  ),
                ),
              )

when navigate out of the view it shows. the error basically caused by photo_view_core.dart,, the following is a part of the stack trace:

#0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure>
package:flutter/…/widgets/framework.dart:4153
#1      Element._debugCheckStateIsActiveForAncestorLookup
package:flutter/…/widgets/framework.dart:4167
#2      Element.getElementForInheritedWidgetOfExactType
package:flutter/…/widgets/framework.dart:4193
#3      TickerMode.getNotifier
package:flutter/…/widgets/ticker_provider.dart:96
#4      TickerProviderStateMixin._updateTickerModeNotifier
package:flutter/…/widgets/ticker_provider.dart:327
#5      TickerProviderStateMixin.createTicker
package:flutter/…/widgets/ticker_provider.dart:291
#6      new AnimationController
package:flutter/…/animation/animation_controller.dart:246
#7      PhotoViewCoreState._scaleAnimationController
package:photo_view/…/core/photo_view_core.dart:112 ------- here
#8      PhotoViewCoreState._scaleAnimationController (package:photo_view[/src/core/photo_view_core.dart]()) // here
package:photo_view/…/core/photo_view_core.dart:1
#9      PhotoViewCoreState.dispose
package:photo_view/…/core/photo_view_core.dart:274
#10     StatefulElement.unmount
package:flutter/…/widgets/framework.dart:4983
#11     _InactiveElements._unmount
package:flutter/…/widgets/framework.dart:1926
#12     _InactiveElements._unmount.<anonymous closure>
package:flutter/…/widgets/framework.dart:1924
#13     ComponentE

bdairy avatar Feb 17 '22 20:02 bdairy

@bdairy same issue for photo_view: https://github.com/bluefireteam/photo_view/issues/502 It is flutter v2.10.0 compatibility non critical error for temporary solution you can try add to pubspec:

dependency_overrides:
  photo_view:
    git:
      url: https://github.com/bluefireteam/photo_view
      ref: master

SergeShkurko avatar Feb 19 '22 06:02 SergeShkurko

@SergeShkurko thanks for the reply,, this does not work,, I had to create a fork over pdfx and change the dependecy of photo_view ,,, then import my fork in pubspec...and the issue causes red screen in big projects,, also it affects all other navigation happens after it.. so it is kinda big deal..

bdairy avatar Feb 19 '22 09:02 bdairy

Same problem here @SergeShkurko any workarounds?

Christyansoft avatar Feb 22 '22 20:02 Christyansoft

Here is a temporary fix https://stackoverflow.com/questions/70404718/error-with-photoview-looking-up-a-deactivated-widgets-ancestor-is-unsafe/71010204#71010204 Its working with external packages and dependency version problems.

nekomaruh avatar Feb 23 '22 16:02 nekomaruh

Works normally, i rechecked Temporary solution, wait new release

dependency_overrides:
  photo_view:
    git:
      url: https://github.com/bluefireteam/photo_view
      ref: master

SergeShkurko avatar Mar 02 '22 04:03 SergeShkurko