Search packages, repositories and app categories

Package detailsv1.0.1

should_rebuild

A widget can prevent Child Widget unnecessary rebuild.You can customize the rebuild conditions。

AndroidiOSWebmacOSWindowsLinux
30-day downloads
899
Likes
29
Pub points
140

Install package

flutter pub add should_rebuild

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The should_rebuild package enhances Flutter performance by allowing widgets to control when their children should rebuild. It provides a way to define custom conditions for rebuilding, preventing unnecessary widget tree updates. This is particularly useful in complex UIs where frequent rebuilds can impact performance. By wrapping child widgets with a condition-based rebuild guard, developers can optimize rendering and reduce computational overhead. The package supports all major platforms and integrates seamlessly into existing Flutter projects.

Use cases

  • Optimizing complex UIs with frequent rebuilds
  • Reducing unnecessary widget updates in lists
  • Improving performance in stateful widgets
  • Customizing rebuild logic based on specific conditions
  • Minimizing render cost in large widget trees

Key features

  • Customizable rebuild conditions
  • Prevents unnecessary child rebuilds
  • Simple integration with existing widgets
  • Cross-platform support
  • Lightweight and efficient

Suitable for

  • Developers optimizing app performance
  • Teams managing large Flutter codebases
  • Apps with dynamic or frequently updated UIs
  • Builders seeking fine-grained control over widget updates
  • Projects requiring minimal boilerplate for rebuild logic

Considerations

  • Requires careful condition logic to avoid missed updates
  • May add complexity if overused
  • Not needed for simple or static widgets
  • Best used in performance-critical sections
  • Needs understanding of Flutter's build lifecycle

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

ShouldRebuild

Star this Repo pub package License GitHub issues GitHub forks

A widget can prevent Child Widget unnecessary rebuilds.You can filter whether you need rebuild based on whether the property values received by the old Child Widget and the new Child Widget are equal.

(这个widget可以防止它的child发生不必要的rebuilds,你可以判断新的Child Widget和旧的Child Widget接收的属性值是否相等来过滤是否需要rebuild)

Add dependency
dependencies:
  should_rebuild: 1.0.1

Or

dependencies:
  should_rebuild:
      git:
        url: https://github.com/fluttercandies/should_rebuild

Super simple to use

ShouldRebuild<Todo>(
    shouldRebuild: (oldWidget, newWidget) => oldWidget.counter != newWidget.counter,
    child: Todo(counter: counter,)
),

Todo Widget

class Todo extends StatelessWidget {
  final int counter;
  Todo({this.counter});
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text(counter.toString()),
    );
  }
}

The Todo widget only rebuilds if counter changes

ShouldRebuild Widget is a generic StatefulWidget,this generic represents the type of Widget returned by the builder method

Categories

Source repository

Projects using this package

No data available yet.