scroll_velocity_notifier 0.0.14 copy "scroll_velocity_notifier: ^0.0.14" to clipboard
scroll_velocity_notifier: ^0.0.14 copied to clipboard

A lightweight Flutter utility that calculates smooth, real-time scroll velocity from scroll notifications, useful for scroll-aware UI and gesture-driven effects.

example/example.md

scroll_velocity_notifier — Examples #

This document demonstrates two common ways to use scroll_velocity_notifier:

  1. Basic usage using a callback
  2. Advanced usage using a custom StreamController

Example 1: Basic Usage (Callback) #

This is the simplest way to use ScrollVelocityProvider.
Scroll velocity is delivered directly through a callback.

import 'package:flutter/material.dart';
import 'package:scroll_velocity_notifier/scroll_velocity_notifier.dart';

void main() {
  runApp(const BasicExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: BasicExampleScreen(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Scroll Velocity – Basic'),
      ),
      body: ScrollVelocityProvider(
        onNotification: (notification, velocity) {
          debugPrint('Scroll velocity: $velocity px/s');
          return false;
        },
        child: ListView.builder(
          itemCount: 50,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text('Item $index'),
            );
          },
        ),
      ),
    );
  }
}

Example 2: Advanced Usage Using A Custom StreamController #

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:scroll_velocity_notifier/scroll_velocity_notifier.dart';

void main() {
  runApp(const StreamControllerExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: StreamControllerExampleScreen(),
    );
  }
}

class StreamControllerExampleScreen extends StatefulWidget {
  const StreamControllerExampleScreen({super.key});

  @override
  State<StreamControllerExampleScreen> createState() =>
      _StreamControllerExampleScreenState();
}

class _StreamControllerExampleScreenState
    extends State<StreamControllerExampleScreen> {
  late final StreamController<ScrollStreamNotification> _controller;
  StreamSubscription<ScrollStreamNotification>? _subscription;

  @override
  void initState() {
    super.initState();

    _controller =
        StreamController<ScrollStreamNotification>.broadcast();

    _subscription = _controller.stream.listen((event) {
      debugPrint(
        'Velocity from stream: ${event.velocity} px/s',
      );
    });
  }

  @override
  void dispose() {
    _subscription?.cancel();
    _controller.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Scroll Velocity – StreamController'),
      ),
      body: ScrollVelocityProvider(
        controller: _controller,
        includeOversScroll: true,
        child: ListView.builder(
          physics: const BouncingScrollPhysics(),
          itemCount: 50,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text('Item $index'),
            );
          },
        ),
      ),
    );
  }
}
3
likes
160
points
287
downloads

Publisher

verified publishercyberail.me

Weekly Downloads

A lightweight Flutter utility that calculates smooth, real-time scroll velocity from scroll notifications, useful for scroll-aware UI and gesture-driven effects.

Repository (GitHub)
View/report issues

Topics

#flutter #scroll #notifications #velocity #user-interface

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on scroll_velocity_notifier