Skip to content

Added a lazy controller in GetBuilder#3463

Open
omedkane wants to merge 1 commit into
jonataslaw:masterfrom
omedkane:perf/lazy-getbuilder-init
Open

Added a lazy controller in GetBuilder#3463
omedkane wants to merge 1 commit into
jonataslaw:masterfrom
omedkane:perf/lazy-getbuilder-init

Conversation

@omedkane

@omedkane omedkane commented Jun 16, 2026

Copy link
Copy Markdown

Added a lazy controller builder in the props of GetBuilder, so that it can build its controller if need be.

Problem ⚠️:

class MyWidget extends StatelessWidget {
  const MyWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      // this will construct every time the widget rebuils, workaround: prop drill or Get.put()
      // This can be inconvenient if it cost a bit or widget is animated and rebuilt a lot of times
      init: MyGetController(),
      global: true,
      builder: (c) => const Placeholder(),
    );
  }
}

Solution ✅:

class MyWidget extends StatelessWidget {
  const MyWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      // This will construct once
      controllerBuilder: () => MyGetController(),
      global: true,
      builder: (c) => const Placeholder(),
    );
  }
}

Pre-launch Checklist

  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or @jonataslaw said the PR is test-exempt.
  • All existing and new tests are passing.

@omedkane omedkane marked this pull request as draft June 16, 2026 19:45
@omedkane omedkane force-pushed the perf/lazy-getbuilder-init branch from eab27d4 to aca0ff0 Compare June 16, 2026 19:47
@omedkane omedkane marked this pull request as ready for review June 16, 2026 19:47
@omedkane omedkane marked this pull request as draft June 16, 2026 19:47
@omedkane omedkane force-pushed the perf/lazy-getbuilder-init branch from aca0ff0 to 55ae3b7 Compare June 16, 2026 19:48
@omedkane omedkane marked this pull request as ready for review June 16, 2026 19:48
@omedkane omedkane force-pushed the perf/lazy-getbuilder-init branch from 55ae3b7 to 2aa766a Compare June 16, 2026 19:48
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

Successfully merging this pull request may close these issues.

1 participant