Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unhandled Exception: Exception: Please provide ShowCaseView context in flutter

I'm trying to use the package ShowoCaseView in a flutter application, here are the steps I've made :

  GlobalKey _oneShowcaseKey = GlobalKey();

  startShowCase() {
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      ShowCaseWidget.of(context).startShowCase([_oneShowcaseKey]);
    });
  }

  @override
  void initState() {
startShowCase();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return ShowCaseWidget(
        builder: Builder(
      builder: (context) => Scaffold(
                                child: Showcase(
                                  key: _oneShowcaseKey,
                                  title: 'Menu',
                                  description: 'Click here to see menu options',
                                  child: Column())

)

this is the way I've implemented the package in my application, but I get this error :

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Exception: Please provide ShowCaseView context
like image 937
Ahmed Wagdi Avatar asked Nov 07 '22 02:11

Ahmed Wagdi


1 Answers

I also got issue.
I changed to write "ShowCaseWIdget" into parent widget as follows, this issue is solved.

class SolvedStatelessWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: ShowCaseWidget(
            builder: Builder(builder: (context) => SolvedStatefulWidget())));
  }
}

class SolvedStatefulWidget extends StatefulWidget {
  @override
  _SolvedStatefulWidgetState createState() => _SolvedStatefulWidgetState();
}

class _SolvedStatefulWidgetState extends State<SolvedStatefulWidget> {
      GlobalKey _oneShowcaseKey = GlobalKey();
    
      startShowCase() {
        WidgetsBinding.instance.addPostFrameCallback((_) async {
          ShowCaseWidget.of(context).startShowCase([_oneShowcaseKey]);
        });
      }
    
      @override
      void initState() {
        startShowCase();
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        super.build(context);
        return yourWidget()
    
    )
like image 115
Nick Avatar answered Nov 15 '22 08:11

Nick