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

[visibility_detector] Incorrect Visibility info Bug after updating to 4.0.0 or later #524

Open
tolotrasamuel opened this issue Apr 11, 2024 · 0 comments

Comments

@tolotrasamuel
Copy link

tolotrasamuel commented Apr 11, 2024

Problem description

Package: visibility_detector

Steps to reproduce

  1. I made a reproducible example:
import 'package:flutter/material.dart';
import 'package:visibility_detector/visibility_detector.dart';


class LogoItem extends StatefulWidget {
  final int id;
  const LogoItem({super.key, required this.id});

  @override
  State<LogoItem> createState() => _LogoItemState();
}

class _LogoItemState extends State<LogoItem> {
  bool visible = true;

  @override
  Widget build(BuildContext context) {
    final key = Key("logo_${widget.id}");
    return Container(
      color: Colors.grey,
      child: VisibilityDetector(
        // key: UniqueKey(),
        key: key,
        onVisibilityChanged: (info) {
          final visible = info.visibleFraction > 0;
          if (visible == this.visible) {
            return;
          }
          print("Visibility changed to $visible ${info.visibleFraction} ${info.size} ${info.visibleBounds}");
          this.visible = visible;
          setState(() {

          });
        },
        child: _buildLogo(),
      ),
    );
  }
  Widget _buildLogo() {
    if (!visible) {
      return const SizedBox.square(dimension: 300, child: Placeholder());
    }
    return  Stack(
      children: [
        const FlutterLogo(size: 300),
        Text("Logo ${widget.id}", style: const TextStyle(color: Colors.white, fontSize: 20)),
      ],
    );
  }
}


class VisibilityDetectorBug extends StatelessWidget {
  const VisibilityDetectorBug({super.key});

  static const row = 5;
  static const column = 5;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Interactive Viewer with Visibility Detector Bug'),
      ),
      body: InteractiveViewer(
        minScale: 0.01,
        boundaryMargin: const EdgeInsets.all(double.infinity),
        constrained: false,
        child:  Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: List.generate(row, (rowIndex) {
            return Row(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: List.generate(column, (colIndex) {
                final id = rowIndex * column + colIndex;
                return LogoItem(id: id);
              }),
            );
          })
        ),
      ),
    );
  }
}

Expected behavior

In version 0.3.3, It works correctly as shown in the video:

working.mp4

Actual behavior

In version 0.4.0 and after, It outputs incorrect values as shown in the video

bug.mp4

Environment

Faced this on Android. Didn't test other platform.
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.0 23A344 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

Additional details

N/A

@tolotrasamuel tolotrasamuel changed the title [visibility_detector] Incorrect Visibility info Bug after updating to 4.0.0 [visibility_detector] Incorrect Visibility info Bug after updating to 4.0.0 or later Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant