3

I have an overlay widget which I'll show on another screen. It is activated using a button that calls a function in the loader class, which sets the visibility of my overlay widget. but when I click on that overlay widget, I'm getting this message:

"The following assertion was thrown while finalizing the widget tree: Looking up a deactivated widget's ancestor is unsafe.

At this point the state of the widget's element tree is no longer stable.

To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method"

I know something is wrong with the context, but I'm not able to figure it out. Can someone help me?


import 'package:animated_widgets/animated_widgets.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';

import 'loader.dart';

class OverlayImage extends StatelessWidget {
  const OverlayImage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<bool>(
      valueListenable: Loader.appLoader.loaderShowingNotifier,
      builder: (context, value, child) {
        if (value) {
          return OpacityAnimatedWidget(
            curve: Curves.linear,
            duration: const Duration(milliseconds: 250),
            enabled: value,
            child: GestureDetector(
                onTap: () => Loader.appLoader.hideLoader(),
                child: yourOverLayWidget()),
          );
        } else {
          return Container();
        }
      },
    );
  }

  Widget yourOverLayWidget() {
    return Stack(
      children: <Widget>[
        Positioned.fill(
          child: BackdropFilter(
            filter: ImageFilter.blur(sigmaX: 8, sigmaY: 8),
            child: Container(
              color: Colors.black.withOpacity(0.5),
            ),
          ),
        ),
        Center(
          child: ValueListenableBuilder<String>(
            builder: (context, value, child) {
              return PhotoView(
                backgroundDecoration:
                    BoxDecoration(color: Colors.black.withOpacity(0.4)),
                imageProvider: NetworkImage(value),
                minScale: PhotoViewComputedScale.contained * 0.85,
                maxScale: PhotoViewComputedScale.covered * 2,
              );
            },
            valueListenable: Loader.appLoader.loaderImageURLNotifier,
          ),
        ),
      ],
    );
  }
}
Arya D
  • 31
  • 1
  • Does this answer your question? [Looking up a deactivated widget's ancestor is unsafe](https://stackoverflow.com/questions/54617432/looking-up-a-deactivated-widgets-ancestor-is-unsafe) – Ruchit Feb 23 '22 at 04:08
  • you have a silly mistake in here "yourOverLayWidget -> yourOverLayWidget(BuildContext context)" just do like and solve your problem also follow this link-> https://stackoverflow.com/a/56103801/6344119 – Saiful Islam Feb 23 '22 at 04:20

0 Answers0