Skip to content

Commit

Permalink
Update deprecations, refactor nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
nohli committed Sep 11, 2024
1 parent eeb3b21 commit f6a665e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 7 additions & 7 deletions packages/fluttium/lib/src/tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Tester {

final Registry _registry;

SemanticsOwner get _semanticsOwner => _binding.pipelineOwner.semanticsOwner!;
SemanticsOwner? get _semanticsOwner =>
RendererBinding.instance.rootPipelineOwner.semanticsOwner;

/// The current screen's media query information.
MediaQueryData get mediaQuery =>
Expand Down Expand Up @@ -103,23 +104,23 @@ class Tester {
///
/// The [text] can be a [String] that can also be used as a [RegExp].
Future<SemanticsNode?> find(String text, {Duration? timeout}) async {
var nodes = _findNodes(_semanticsOwner.rootSemanticsNode!, text);
var nodes = _findNodes(_semanticsOwner?.rootSemanticsNode, text);

final end = clock.now().add(timeout ?? const Duration(seconds: 10));
while (nodes.isEmpty) {
await pump();
if (clock.now().isAfter(end)) {
return null;
}
nodes = _findNodes(_semanticsOwner.rootSemanticsNode!, text);
nodes = _findNodes(_semanticsOwner?.rootSemanticsNode, text);
}

return nodes.first;
}

List<SemanticsNode> _findNodes(SemanticsNode node, String text) {
List<SemanticsNode> _findNodes(SemanticsNode? node, String text) {
final nodes = <SemanticsNode>[];
node.visitChildren((n) {
node?.visitChildren((n) {
// Add all descendants that match the pattern.
if (!n.mergeAllDescendantsIntoThisNode) {
nodes.addAll(_findNodes(n, text));
Expand Down Expand Up @@ -169,8 +170,7 @@ class Tester {

/// Wait for the semantics tree to be fully build.
Future<void> ready() async {
while (_binding.pipelineOwner.semanticsOwner == null ||
_binding.pipelineOwner.semanticsOwner!.rootSemanticsNode == null) {
while (_semanticsOwner?.rootSemanticsNode == null) {
await _binding.endOfFrame;
}
}
Expand Down
12 changes: 8 additions & 4 deletions packages/fluttium/test/src/tester_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ void main() {
semanticsOwner = _MockSemanticsOwner();

final pipelineOwner = _MockPipelineOwner();
when(() => binding.pipelineOwner).thenReturn(pipelineOwner);
when(() => RendererBinding.instance.rootPipelineOwner)
.thenReturn(pipelineOwner);
when(() => pipelineOwner.semanticsOwner).thenReturn(semanticsOwner);

rootNode = MockSemanticsNode();
Expand Down Expand Up @@ -493,7 +494,8 @@ void main() {
semanticsOwner = _MockSemanticsOwner();

final pipelineOwner = _MockPipelineOwner();
when(() => binding.pipelineOwner).thenReturn(pipelineOwner);
when(() => RendererBinding.instance.rootPipelineOwner)
.thenReturn(pipelineOwner);
when(() => pipelineOwner.semanticsOwner).thenReturn(semanticsOwner);

rootNode = MockSemanticsNode();
Expand All @@ -503,7 +505,8 @@ void main() {
test('resolve when ready', () {
expect(tester.ready(), completes);

verify(() => binding.pipelineOwner.semanticsOwner).called(equals(2));
verify(() => RendererBinding.instance.rootPipelineOwner.semanticsOwner)
.called(equals(2));
verify(() => semanticsOwner.rootSemanticsNode).called(equals(1));
});

Expand All @@ -515,7 +518,8 @@ void main() {

expect(tester.ready(), completes);

verify(() => binding.pipelineOwner.semanticsOwner).called(equals(2));
verify(() => RendererBinding.instance.rootPipelineOwner.semanticsOwner)
.called(equals(2));
verify(() => semanticsOwner.rootSemanticsNode).called(equals(1));
verify(() => binding.endOfFrame).called(equals(1));
});
Expand Down

0 comments on commit f6a665e

Please sign in to comment.