Skip to content

Commit

Permalink
renamed optimized to withChild
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Molchanovsky committed Nov 19, 2023
1 parent fc46ddc commit a854fa6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions flutter_mobx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## 2.2.0
- `Observer` is updated with the new `Observer.optimized` constructor, so you can exclude child branch from the re-rendering. - [@subzero911](https://github.com/subzero911) \
In case if you use `Builder.optimized`, you should provide two parameters: `builderOptimized` and `child`:
- `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`:
```dart
Observer.optimized(
builderOptimized: (context, child) => FooWidget(foo: foo, child: child),
Observer.withChild(
builderWithChild: (context, child) => FooWidget(foo: foo, child: child),
child: BarWidget(), // is not rebuilt
),
```
Expand Down
14 changes: 7 additions & 7 deletions flutter_mobx/lib/src/observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Observer extends StatelessObserverWidget {
String? name,
bool? warnWhenNoObservables,
}) : debugConstructingStackFrame = debugFindConstructingStackFrame(),
builderOptimized = null,
builderWithChild = null,
child = null,
assert(builder != null),
super(
Expand All @@ -35,15 +35,15 @@ class Observer extends StatelessObserverWidget {

/// Observer which excludes the child branch
// ignore: prefer_const_constructors_in_immutables
Observer.optimized({
Observer.withChild({
Key? key,
required this.builderOptimized,
required this.builderWithChild,
required this.child,
String? name,
bool? warnWhenNoObservables,
}) : debugConstructingStackFrame = debugFindConstructingStackFrame(),
builder = null,
assert(builderOptimized != null && child != null),
assert(builderWithChild != null && child != null),
super(
key: key,
name: name,
Expand All @@ -52,9 +52,9 @@ class Observer extends StatelessObserverWidget {

final WidgetBuilder? builder;

final TransitionBuilder? builderOptimized;
final TransitionBuilder? builderWithChild;

/// The child widget to pass to the [builderOptimized].
/// The child widget to pass to the [builderWithChild].
final Widget? child;

/// The stack frame pointing to the source that constructed this instance.
Expand All @@ -68,7 +68,7 @@ class Observer extends StatelessObserverWidget {
: '');

@override
Widget build(BuildContext context) => builderOptimized?.call(context, child) ?? builder!.call(context);
Widget build(BuildContext context) => builderWithChild?.call(context, child) ?? builder!.call(context);

/// Matches constructor stack frames, in both VM and web environments.
static final _constructorStackFramePattern = RegExp(r'\bnew\b');
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 @@ -67,8 +67,8 @@ void main() {

await tester.pumpWidget(
MaterialApp(
home: Observer.optimized(
builderOptimized: (context, child) {
home: Observer.withChild(
builderWithChild: (context, child) {
return Column(
children: [
ElevatedButton(onPressed: () => message.value = 'Clicked', child: Container()),
Expand Down

0 comments on commit a854fa6

Please sign in to comment.