12

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
Srilal Sachintha
  • 1,335
  • 1
  • 12
  • 18
Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116

3 Answers3

5

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()
    
    )
Nick
  • 51
  • 2
3

Don't wrap your Scaffold inside ShowCaseWidget. Instead, do this wrapping to main navigation point.

For example: Using onGenerateRoute:

return setTransition(ShowCaseWidget(
        builder: Builder(
          builder: (_) => DashboardView(map),
        ),
      ));

Hope this fixes your issue, ask you if you still find any issue.

0

Make sure the Showcase widget that uses this key, is actually presented on the screen or is rendered. For me it happened when a screen was presented in a way that didn't render the Showcase widget, but was still calling the startShowCase method.

Almog C
  • 795
  • 6
  • 14