Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observer excludedchild #958

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions flutter_mobx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## 2.2.0+1
- renamed `Observer.withChild` to `Observer.excludedChild`
`
## 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.excludedChild` constructor, so you can exclude child branch from the re-rendering. - [@subzero911](https://github.com/subzero911) \
In case if you use `Observer.excludedChild`, you should provide two parameters: `builderWithChild` and `child`:
```dart
Observer.withChild(
Observer.excludedChild(
subzero911 marked this conversation as resolved.
Show resolved Hide resolved
builderWithChild: (context, child) => FooWidget(foo: foo, child: child),
child: BarWidget(), // is not rebuilt
),
Expand Down
4 changes: 3 additions & 1 deletion flutter_mobx/lib/src/observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Observer extends StatelessObserverWidget {

/// Observer which excludes the child branch
// ignore: prefer_const_constructors_in_immutables
Observer.withChild({
Observer.excludedChild({
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.excludedChild'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.excludedChild(
builderWithChild: (context, child) {
return Column(
children: [
Expand Down