Pass Riverpod WidgetRef To A Controller

Поделиться
HTML-код
  • Опубликовано: 9 янв 2025

Комментарии • 5

  • @HuotChhay-is5bx
    @HuotChhay-is5bx Год назад

    What editor theme you use?

  • @agreensh
    @agreensh Год назад

    Will only work if inside the same context eg inside another builder (in the build method) can fail, as the context has changed.

    • @dbestech
      @dbestech  Год назад +3

      Instead of InitState(), you may also initialize the controller inside DidChangeDependencies() method. this way, if the context changes, you still get it.

  • @crazy-man
    @crazy-man Год назад

    it's easier to just wrap the widget in a Consumer (
    builder: (BuildContext context, WidgetRef ref, Widget? child) { },
    )
    and ref and context get

    • @dbestech
      @dbestech  Год назад +1

      yes, that's not the point. The point is passing the ref object to another class globally