【问题标题】:Unhandled Exception: Exception: Please provide ShowCaseView context in flutter未处理的异常:异常:请在颤动中提供 ShowCaseView 上下文
【发布时间】:2021-02-06 12:47:01
【问题描述】:

我正在尝试在颤振应用程序中使用包 ShowoCaseView,这是我所做的步骤:

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

)

这是我在应用程序中实现包的方式,但出现此错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Exception: Please provide ShowCaseView context

【问题讨论】:

    标签: flutter dart showcaseview


    【解决方案1】:

    我也遇到了问题。
    我更改为将“ShowCaseWIdget”写入父小部件,如下所示,此问题已解决。

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

    【讨论】:

      【解决方案2】:

      不要将 Scaffold 包裹在 ShowCaseWidget 中。相反,请将此包装到主导航点。

      例如: 使用 onGenerateRoute:

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

      希望这能解决您的问题,如果您仍然发现任何问题,请询问您。

      【讨论】:

        猜你喜欢
        • 2021-04-12
        • 2020-06-24
        • 2019-11-27
        • 2021-06-21
        • 2019-10-05
        • 2021-11-20
        • 2019-07-25
        • 2016-05-30
        • 1970-01-01
        相关资源
        最近更新 更多