Skip to content

Commit

Permalink
Observer excludedchild (mobxjs#958)
Browse files Browse the repository at this point in the history
* rename to excludedChild

* version

* withBuiltChild

---------

Co-authored-by: Sergey Molchanovsky <[email protected]>
Co-authored-by: Pavan Podila <[email protected]>
  • Loading branch information
3 people authored Nov 30, 2023
1 parent d7dbbf5 commit 74e4a89
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
13 changes: 8 additions & 5 deletions flutter_mobx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## 2.2.0+1
- renamed `Observer.withChild` to `Observer.withBuiltChild`
`
## 2.2.0
- `Observer` is updated with the new `Observer.withChild` constructor, so you can exclude child branch from the re-rendering. - [@subzero911](https://github.com/subzero911) \
In case if you use `Builder.withChild`, you should provide two parameters: `builderWithChild` and `child`:
- `Observer` is updated with the new `Observer.withBuiltChild` constructor, so you can exclude child branch from the re-rendering. - [@subzero911](https://github.com/subzero911) \
In case if you use `Observer.withBuiltChild`, you should provide two parameters: `builderWithChild` and `child`:
```dart
Observer.withChild(
builderWithChild: (context, child) => FooWidget(foo: foo, child: child),
child: BarWidget(), // is not rebuilt
Observer.withBuiltChild(
builderWithChild: (context, child) => FooWidget(foo: foo, bar: child),
child: BarWidget(), // won't rebuild
),
```

Expand Down
6 changes: 4 additions & 2 deletions flutter_mobx/lib/src/observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class Observer extends StatelessObserverWidget {
warnWhenNoObservables: warnWhenNoObservables,
);

/// Observer which excludes the child branch
/// Observer which excludes the child branch from being rebuilt
// ignore: prefer_const_constructors_in_immutables
Observer.withChild({
Observer.withBuiltChild({
Key? key,
required this.builderWithChild,
required this.child,
Expand All @@ -50,8 +50,10 @@ class Observer extends StatelessObserverWidget {
warnWhenNoObservables: warnWhenNoObservables,
);

/// regular builder, suitable for most cases
final WidgetBuilder? builder;

/// builder function with child parameter
final TransitionBuilder? builderWithChild;

/// The child widget to pass to the [builderWithChild].
Expand Down
2 changes: 1 addition & 1 deletion flutter_mobx/lib/version.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated via set_version.dart. !!!DO NOT MODIFY BY HAND!!!

/// The current version as per `pubspec.yaml`.
const version = '2.2.0';
const version = '2.2.0+1';
2 changes: 1 addition & 1 deletion flutter_mobx/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flutter_mobx
description:
Flutter integration for MobX. It provides a set of Observer widgets that automatically rebuild
when the tracked observables change.
version: 2.2.0
version: 2.2.0+1

homepage: https://github.com/mobxjs/mobx.dart
issue_tracker: https://github.com/mobxjs/mobx.dart/issues
Expand Down
4 changes: 2 additions & 2 deletions flutter_mobx/test/flutter_mobx_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ void main() {
expect(renderCount, equals(1));
});

testWidgets("Observer.withChild's child doesn't re-render", (tester) async {
testWidgets("Observer.withBuiltChild's child doesn't re-render", (tester) async {
final message = Observable('Click');
final key1 = UniqueKey();
final key2 = UniqueKey();
final key3 = UniqueKey();

await tester.pumpWidget(
MaterialApp(
home: Observer.withChild(
home: Observer.withBuiltChild(
builderWithChild: (context, child) {
return Column(
children: [
Expand Down

0 comments on commit 74e4a89

Please sign in to comment.