简体   繁体   中英

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

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()
    
    )

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM