Flutter: showGeneralDialog does not share a context with the location that showGeneralDialog is originally called from Flutter: showGeneralDialog does not share a context with the location that showGeneralDialog is originally called from dart dart

Flutter: showGeneralDialog does not share a context with the location that showGeneralDialog is originally called from


correct way :

void _showSignOutAlert(BuildContext context) {  final CapturedThemes themes = InheritedTheme.capture(    from: context,    to: Navigator.of(        context,        rootNavigator: true,    ).context,  );  showGeneralDialog(    barrierColor: Colors.black.withOpacity(0.5),    transitionBuilder: (context, a1, a2, widget) {      return Transform.scale(        scale: a1.value,        child: Opacity(          opacity: a1.value,          child: widget,        ),      );    },    transitionDuration: Duration(milliseconds: 250),    barrierDismissible: true,    context: context,    pageBuilder: (context, animation1, animation2) {      return themes.wrap(Builder(        builder: (context) => CustomWidget(),      ));    },  );}

pay attention to :

CapturedThemes and themes.wrap


I did manage to pass the context, by doing so:

  void _showSignOutAlert(BuildContext superContext) {    showGeneralDialog(      barrierColor: Colors.black.withOpacity(0.5),      transitionBuilder: (context, a1, a2, widget) {        return Transform.scale(          scale: a1.value,          child: Opacity(            opacity: a1.value,            child: CustomWidget(superContext: superContext),          ),        );      },      transitionDuration: Duration(milliseconds: 250),      barrierDismissible: true,      context: superContext,      pageBuilder: (context, animation1, animation2) {        return null;      },    );  }

And then using the superContext in the CustomWidget to call Provider.of<State>(superContext)

But if anyone has another solution, I'd gladly hear it