Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to wait for the page widgets to load? #56

Open
rignaneseleo opened this issue Dec 28, 2023 · 3 comments
Open

How to wait for the page widgets to load? #56

rignaneseleo opened this issue Dec 28, 2023 · 3 comments

Comments

@rignaneseleo
Copy link

Hi, I'm using this library on the home screen of an app. The homescreen has some widgets that get loaded dynamically based on what's fetched on the server.

Each home widget has the following build logic:

@override
  Widget build(BuildContext context, WidgetRef ref) {
    if (qod == null) {
      return const SizedBox();
    }
    
    //return the actual widget
  }

If I wrap this whole widget into a Focus node, I get only a tiny dot highlighted (which probably corresponds to the empty SizedBox(). If I wrap only the actual box, I get the grey overlay without any highlight at all.

I guess this happens because at the time the Onboarding widget is initialized, the focusnodes are wrapping something that either will change (SizedBox) or doesn't exists yet (the actual widget).

How can I solve this problem?

I tried to call the show() function after a delay, but nothing has changed:

 @override
  void initState() {
    super.initState();

    Future.delayed(const Duration(milliseconds: 500), () {
      final OnboardingState? onboarding = Onboarding.of(context);
      if (onboarding != null) {
        onboarding.show();
      }
    });
  }
@TheMaverickProgrammer
Copy link

Did you ever find a solution? I'm having a similar problem.

@chriscarman-mp
Copy link

Same here, on Android it seems fine but there's an issue on iOS which has slightly longer/different page load animations. I can remove the animations but would rather find a better solution, and not just using a delay and it's inconsistent and inaccurate.

@chriscarman-mp
Copy link

So, I may have stumbled across a solution

Future<void> waitForRenderSettled() async {
    // Loop until there are no scheduled frames
    while (SchedulerBinding.instance.hasScheduledFrame) {
      // Wait for the end of the current frame
      await SchedulerBinding.instance.endOfFrame;
    }
  }

Use it like this

await waitForRenderSettled();

// Do your thing ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants