Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 为什么showcaseview在第一次尝试时抛出错误?_Flutter - Fatal编程技术网

Flutter 为什么showcaseview在第一次尝试时抛出错误?

Flutter 为什么showcaseview在第一次尝试时抛出错误?,flutter,Flutter,嘿,我正在我的应用程序中使用ShowCaseView。当我第一次打开我的应用程序时,注册后没有显示showcase,甚至没有显示应该显示的图标。但当我关闭应用程序并再次打开它时,它工作得很好 这是指showcase的代码: class _HomeSearchPageState extends State<HomeSearchPage> { final keyOne = GlobalKey(); void initState() { super.initState

嘿,我正在我的应用程序中使用ShowCaseView。当我第一次打开我的应用程序时,注册后没有显示showcase,甚至没有显示应该显示的图标。但当我关闭应用程序并再次打开它时,它工作得很好

这是指showcase的代码:

class _HomeSearchPageState extends State<HomeSearchPage> {

  final keyOne = GlobalKey();


  void initState() {
    super.initState();

  WidgetsBinding.instance.addPostFrameCallback(
    (_) => ShowCaseWidget.of(context).startShowCase([
      keyOne,
    ]),
  );
这些错误是循环的,所以调试控制台总是显示它们。
第一个应用程序打开和第二个应用程序打开之间的唯一区别是:在第一个应用程序打开中,用户进入一个注册页面,然后使用showcaseview进入该页面。在第二种情况下,用户直接使用showcaseview进入页面。这会如何影响showcase?更准确地说,为什么会抛出错误?

不确定我们是否有类似的问题,但也许我的答案会对您有所帮助:)。当我导航到拥有Showcase小部件的页面时,会出现此问题,但当我从另一个页面“返回”到该页面时,不会出现此问题

也许您可以检查“如果您没有使用ShowCaseWidget包装您的小部件,则会引发此错误。这不是包本身的问题。”

因此,我尝试提高main.dart中ShowCaseWidget的级别,问题就解决了

void main() {
  // runApp(MyApp());
  runApp(
    ShowCaseWidget(
      autoPlay: false,
      autoPlayDelay: Duration(seconds: 8),
      autoPlayLockEnable: false,
      builder: Builder(
        builder: (context) => MyApp(),
      ),
      onStart: (index, key) {
        print('onStart: $index, $key');
      },
      onComplete: (index, key) {
        print('onComplete: $index, $key');
      },
    ),
  );
}
到目前为止,该应用程序仍然运行良好。如果发生任何问题,我将在这里再次报告

    ════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building IconTheme(color: Color(0xffffffff)):
The getter 'activeWidgetIds' was called on null.
Receiver: null
Tried calling: activeWidgetIds

    The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
When the exception was thrown, this was the stack
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      ShowCaseWidget.activeTargetWidget
package:showcaseview/showcase_widget.dart:51
#2      _ShowcaseState.showOverlay
package:showcaseview/showcase.dart:171
#3      _ShowcaseState.didChangeDependencies
package:showcaseview/showcase.dart:164
#4      StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4786

════════ Exception caught by rendering library ═════════════════════════════════
Each child must be laid out exactly once.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by scheduler library ═════════════════════════════════
Exception: Please provide ShowCaseView context



 ════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 6224 pos 12: '_children.contains(child)': is not true.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
void main() {
  // runApp(MyApp());
  runApp(
    ShowCaseWidget(
      autoPlay: false,
      autoPlayDelay: Duration(seconds: 8),
      autoPlayLockEnable: false,
      builder: Builder(
        builder: (context) => MyApp(),
      ),
      onStart: (index, key) {
        print('onStart: $index, $key');
      },
      onComplete: (index, key) {
        print('onComplete: $index, $key');
      },
    ),
  );
}