talamaska / onboarding_overlay

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using Onboarding overlay with GetX

Macacoazul01 opened this issue · comments

I'm changing my code to use get as the navigation manager and screen controller and I'm looking for your suggestion, @talamaska on how is the best way to use your package.

Today, to open the onboarding sequence, i'm using Onboarding.of(context)!.show(); inside of WidgetsBinding.instance!.addPostFrameCallback((_) in the initState of a Stateful widget.

Using the GetxController to handle the functions part of my screen, I won't be able to have this context to call the onboarding.

I don't know if you already used this package and have a solution for this. If you need a sample code, I can generate one.

I'm not really sure how to do that without a context. I'd normally need the context for getting an overlay instance. If i figure out a way to do that without a context I could proceed exposing some features to an OnboardingController. For I'm not aware a good way to do it. I'm open to suggestions and also would look at a possible PR.

I've solved the problem by passing the context when the controller is initialized:

class SecondController extends GetxController {
  SecondController({required this.contexto});
  final BuildContext contexto;

  void start() {
    Onboarding.of(contexto)?.show();
  }

  @override
  void onInit() {
    super.onInit();
    WidgetsBinding.instance!.addPostFrameCallback((_) async {
      start();
    });
  }
}

class Second extends StatelessWidget {
  const Second({Key? key, required this.focus}) : super(key: key);
  final List<FocusNode> focus;

  @override
  Widget build(BuildContext context) {
    final SecondController _editController = Get.put(SecondController(contexto: context));
    
    ....

Sharing the full code if someone needs it on the future

onb.zip

You can close this issue if you want, @talamaska

I will rename the issue to "Using Onboarding overlay with GetX" if someone else search for a receipt.