Skip to content

Commit

Permalink
fix: visibilty bug
Browse files Browse the repository at this point in the history
This commit adds an Alignment parameter to the visibility related methods.
The default setting by Flutter of Alignment.center fails, if hitting a SizedBox.
This can be fixed by specifying an Alignment.
  • Loading branch information
FritzMatthaeus committed Dec 21, 2024
1 parent 79b98c6 commit 6050c87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/patrol_finders/lib/src/custom_finders/patrol_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,13 @@ class PatrolFinder implements MatchFinder {
///
/// Timeout is globally set by [PatrolTester.config.visibleTimeout]. If you
/// want to override this global setting, set [timeout].
///
/// Provide [alignment] to check if the widget is visible in a specific area
/// of the screen. It defaults to [Alignment.center].
Future<PatrolFinder> waitUntilVisible({
Duration? timeout,
bool enablePatrolLog = true,
Alignment alignment = Alignment.center,
}) =>
wrapWithPatrolLog(
action: 'waitUntilVisible',
Expand All @@ -415,6 +419,7 @@ class PatrolFinder implements MatchFinder {
this,
timeout: timeout,
enablePatrolLog: false,
alignment: alignment,
),
enablePatrolLog: enablePatrolLog,
);
Expand Down Expand Up @@ -510,8 +515,11 @@ class PatrolFinder implements MatchFinder {
String describeMatch(Plurality plurality) => finder.describeMatch(plurality);

/// Returns true if this finder finds at least 1 visible widget.
bool get visible {
final isVisible = hitTestable().evaluate().isNotEmpty;
///
/// Provide [alignment] to check if the widget is visible in a specific area
/// of the screen. It defaults to [Alignment.center].
bool visible({Alignment alignment = Alignment.center}) {
final isVisible = hitTestable(at: alignment).evaluate().isNotEmpty;
if (isVisible == true) {
assert(
exists == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,14 @@ class PatrolTester {
///
/// Timeout is globally set by [PatrolTester.config.visibleTimeout]. If you
/// want to override this global setting, set [timeout].
///
/// Provide [alignment] to check if the widget is visible in a specific area
/// of the screen. It defaults to [Alignment.center].
Future<PatrolFinder> waitUntilVisible(
Finder finder, {
Duration? timeout,
bool enablePatrolLog = true,
Alignment alignment = Alignment.center,
}) {
return TestAsyncUtils.guard(
() => wrapWithPatrolLog(
Expand All @@ -503,7 +507,7 @@ class PatrolTester {
function: () async {
final duration = timeout ?? config.visibleTimeout;
final end = tester.binding.clock.now().add(duration);
final hitTestableFinder = finder.hitTestable();
final hitTestableFinder = finder.hitTestable(at: alignment);
while (hitTestableFinder.evaluate().isEmpty) {
final now = tester.binding.clock.now();
if (now.isAfter(end)) {
Expand Down

0 comments on commit 6050c87

Please sign in to comment.