Skip to content

Commit

Permalink
chore: format (#992)
Browse files Browse the repository at this point in the history
* chore: format

* chore: update code formatting command in release documentation

dart-lang/dart_style#986
  • Loading branch information
altynbek132 authored Mar 23, 2024
1 parent fc3c2e7 commit fdfb466
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 171 deletions.
2 changes: 1 addition & 1 deletion docs/docs/development/release.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To format your files following
This will format your code accordingly regardless of your IDE settings.

```
dartfmt -w .
dart format .
```

### 2. pubspec.yaml
Expand Down
20 changes: 10 additions & 10 deletions flutter_mobx/lib/src/observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ class Observer extends StatelessObserverWidget {

@override
String getName() =>
super.getName() +
(debugConstructingStackFrame != null
? '\n$debugConstructingStackFrame'
: '');
super.getName() +
(debugConstructingStackFrame != null
? '\n$debugConstructingStackFrame'
: '');

@override
Widget build(BuildContext context) => builderWithChild?.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 Expand Up @@ -99,15 +100,14 @@ class Observer extends StatelessObserverWidget {
.skip(3)
// Search for the first non-constructor frame
.firstWhere(
(frame) =>
!_constructorStackFramePattern.hasMatch(frame),
(frame) => !_constructorStackFramePattern.hasMatch(frame),
orElse: () => '');

final stackFrameCore =
_stackFrameCleanUpPattern.firstMatch(rawStackFrame)?.group(1);
_stackFrameCleanUpPattern.firstMatch(rawStackFrame)?.group(1);
final cleanedStackFrame = stackFrameCore == null
? null
: 'Observer constructed from: $stackFrameCore';
? null
: 'Observer constructed from: $stackFrameCore';

stackFrame = cleanedStackFrame;
}
Expand Down
80 changes: 42 additions & 38 deletions flutter_mobx/test/flutter_mobx_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,49 @@ void main() {
expect(renderCount, equals(1));
});

testWidgets("Observer.withBuiltChild'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.withBuiltChild(
builderWithChild: (context, child) {
return Column(
children: [
ElevatedButton(onPressed: () => message.value = 'Clicked', child: Container()),
Text(message.value, key: key1),
child!,
Builder(
builder: (context) {
return Text(message.value, key: key3);
}
),
],
);
},
child: Text(message.value, key: key2),
),
),
);

expect(tester.widget<Text>(find.byKey(key1)).data, equals('Click'));
expect(tester.widget<Text>(find.byKey(key2)).data, equals('Click'));
expect(tester.widget<Text>(find.byKey(key3)).data, equals('Click'));

await tester.tap(find.byType(ElevatedButton));
expect(message.value, equals('Clicked'));

await tester.pump();
expect(tester.widget<Text>(find.byKey(key1)).data, equals('Clicked')); // Observer rebuilt the Text1
expect(tester.widget<Text>(find.byKey(key2)).data, equals('Click')); // child Text2 did not change
expect(tester.widget<Text>(find.byKey(key3)).data, equals('Clicked')); // Builder does not preserve from rebuild
final key1 = UniqueKey();
final key2 = UniqueKey();
final key3 = UniqueKey();

await tester.pumpWidget(
MaterialApp(
home: Observer.withBuiltChild(
builderWithChild: (context, child) {
return Column(
children: [
ElevatedButton(
onPressed: () => message.value = 'Clicked',
child: Container()),
Text(message.value, key: key1),
child!,
Builder(builder: (context) {
return Text(message.value, key: key3);
}),
],
);
},
child: Text(message.value, key: key2),
),
),
);

expect(tester.widget<Text>(find.byKey(key1)).data, equals('Click'));
expect(tester.widget<Text>(find.byKey(key2)).data, equals('Click'));
expect(tester.widget<Text>(find.byKey(key3)).data, equals('Click'));

await tester.tap(find.byType(ElevatedButton));
expect(message.value, equals('Clicked'));

await tester.pump();
expect(tester.widget<Text>(find.byKey(key1)).data,
equals('Clicked')); // Observer rebuilt the Text1
expect(tester.widget<Text>(find.byKey(key2)).data,
equals('Click')); // child Text2 did not change
expect(tester.widget<Text>(find.byKey(key3)).data,
equals('Clicked')); // Builder does not preserve from rebuild
});

testWidgets('Observer build should call reaction.track', (tester) async {
Expand Down
7 changes: 5 additions & 2 deletions mobx/lib/src/api/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class StoreConfig {
/// String withEquals = 'world';
/// ```
class MakeObservable {
const MakeObservable({this.readOnly = false, this.equals, this.useDeepEquality = true});
const MakeObservable(
{this.readOnly = false, this.equals, this.useDeepEquality = true});

final bool readOnly;

/// A [Function] to use check whether the value of an observable has changed.
///
/// Must be a top-level or static [Function] that takes two arguments and
Expand Down Expand Up @@ -58,7 +60,8 @@ const MakeObservable observable = MakeObservable();
const MakeObservable readonly = MakeObservable(readOnly: true);

/// Allows a reaction to be fired even if the value hasn't changed.
const MakeObservable alwaysNotify = MakeObservable(equals: observableAlwaysNotEqual);
const MakeObservable alwaysNotify =
MakeObservable(equals: observableAlwaysNotEqual);

/// Internal class only used for code-generation with `mobx_codegen`.
///
Expand Down
Loading

0 comments on commit fdfb466

Please sign in to comment.