talamaska / onboarding_overlay

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't find onboarding widget

BenoitDuffez opened this issue · comments

Here's the error I have:

The following assertion was thrown during a scheduler callback:
No Onboarding widget found.

Accessing the OnboardingState with Onboarding.of(context) needs an Onboarding widget ancestor

The most common way to add an Onboarding to an application is to include it, below MaterialApp widget in the runApp() call.

The context from which that widget was searching for an OnboardingState was: LicheApp

The widget hierarchy is:

image

I have triggered the show from HomePage:

class HomePage extends StatefulWidget {
  const HomePage({super.key, [...], required this.focusNodes});

  // ...
  final List<FocusNode> focusNodes;

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();
 
    WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) {
      print("showing onboarding");
      Onboarding.of(context)?.show();
    });
 }

  ...
}

I also tried to call Onboarding.of(context)?.show() from a button click in the UI but it yields the same result.

I am not sure what I did wrong?

OK, my material app is handled by https://pub.dev/packages/go_router — maybe this isn't supported?

In my gorouter config I changed this:

GoRoute(path: 'xxx', builder: (BuildContext context, GoRouterState state) => HomePage(db: db)),

into this:

var homePage = HomePage(db: db, focusNodes: focusNodes);


final List<OnboardingStep> steps = [
  OnboardingStep(focusNode: focusNodes[0],
  ...
];

GoRoute(path: 'xxx', builder: (BuildContext context, GoRouterState state)
    => Onboarding(key: onboardingKey,steps: steps, child: homePage);

and now it works. I guess I just need to properly insert the Onboarding widget in the tree. Feel free to close if this is the expected behavior.

I had some issues accessing Provided bloc when using go_router, in turned out that the modals are launched with the default navigator, which for some reason doesn't access the same context as go_router. So I don't know.

Gorouter creates the widgets which are then inserted into the tree, so now I'm creating the onboarding wrapper there, and it works. I guess we can close.