0

When I scroll through the news, print is triggered as soon as the card is fully visible. However, if I scroll through the news quickly, causing the scroll to continue by inertia until it reaches the end, prints look like this:

FeedCard 0 visible; FeedCard 1 visible; FeedCard 2 visible; FeedCard 18 visible; FeedCard 19 visible; FeedCard 20 visible;

How can i fix this?

import 'package:visibility_detector/visibility_detector.dart';

class NewsCard extends StatelessWidget {
  const NewsCard({this.id});

  final int? id;

  static List<int?> renderedNewsIds = [];

  @override
  Widget build(BuildContext context) {
    return VisibilityDetector(
      key: Key(id.toString()),
      onVisibilityChanged: (visibility) {
        if (!renderedNewsIds.contains(id)) {
          renderedNewsIds.add(id);
          print('FeedCard $id visible');
        }
      },
      child: SomeNewsItem();
    );
  }
}

I thought the problem was that the cards were not loading in time, but as far as I can see, they are successfully loading, but the VisibilityDetector still doesn't catch them.

0

Browse other questions tagged or ask your own question.