All Projects → rvamsikrishna → Inview_notifier_list

rvamsikrishna / Inview_notifier_list

Licence: mit
A Flutter package that builds a list view and notifies when the widgets are on screen.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Inview notifier list

Flutter Ui Nice
More than 130+ pages in this beautiful app and more than 45 developers has contributed to it.
Stars: ✭ 3,092 (+1049.44%)
Mutual labels:  package, listview
List view item builder
Flutter package: Item builder for ListView,to quickly build header & item & footer,and provide jumpTo(index) function.
Stars: ✭ 31 (-88.48%)
Mutual labels:  package, listview
Django Notifications
GitHub notifications alike app for Django
Stars: ✭ 1,237 (+359.85%)
Mutual labels:  package, notification
React Native Pagination
Animated Pagination For React Native's ListView, FlatList, and SectionList
Stars: ✭ 296 (+10.04%)
Mutual labels:  scroll, listview
Update Check
Minimalistic update notifications for command line interfaces
Stars: ✭ 145 (-46.1%)
Mutual labels:  package, notification
qualscan
A CLI, and API, tool to run many quality check-ups on your javascript project.
Stars: ✭ 20 (-92.57%)
Mutual labels:  package
Validus
A dead simple Python string validation library.
Stars: ✭ 257 (-4.46%)
Mutual labels:  package
aplus
Aplus Command Line Tool
Stars: ✭ 71 (-73.61%)
Mutual labels:  package
route observer mixin
RouteObserveMixin provides easy access to didPush/didPop/didPushNext/didPopNext.
Stars: ✭ 27 (-89.96%)
Mutual labels:  package
Wechat tweak
♨️ iOS版功能最全的微信插件,支持最新版微信,具备自动抢红包,屏蔽消息和群消息,过滤特定的群聊,防止撤回消息,伪定位 (朋友圈和附近的人),修改微信运动步数和实时取景做聊天页的背景等功能。
Stars: ✭ 265 (-1.49%)
Mutual labels:  package
postcss-momentum-scrolling
PostCSS plugin add 'momentum' style scrolling behavior (-webkit-overflow-scrolling: touch) for elements with overflow (scroll, auto) on iOS
Stars: ✭ 69 (-74.35%)
Mutual labels:  scroll
larafy
Larafy is a Laravel package for Spotify API. It is more like a wrapper for the Spotify API.
Stars: ✭ 53 (-80.3%)
Mutual labels:  package
Construct
A PHP project/micro-package generator for PDS compliant projects or micro-packages.
Stars: ✭ 257 (-4.46%)
Mutual labels:  package
UUAmountBoardView
[iOS]带有数字(金额)滚动效果的UI控件
Stars: ✭ 37 (-86.25%)
Mutual labels:  scroll
Phytouch
Smooth scrolling, rotation, pull to refresh, page transition and any motion for the web - 丝般顺滑的触摸运动方案
Stars: ✭ 2,854 (+960.97%)
Mutual labels:  scroll
website-change-monitor
Monitor a website and get email and Slack notifications when specific changes are detected
Stars: ✭ 104 (-61.34%)
Mutual labels:  notification
ansible-role-rsyslog
Install and configure rsyslog on your system.
Stars: ✭ 14 (-94.8%)
Mutual labels:  package
Laravel Transactional Events
Transaction-aware Event Dispatcher for Laravel
Stars: ✭ 263 (-2.23%)
Mutual labels:  package
laravel-blade-sugar
Add syntactic sugar to your Laravel Blade templates.
Stars: ✭ 16 (-94.05%)
Mutual labels:  package
laravel-username-generator
Automatically generate usernames for Laravel User Model
Stars: ✭ 37 (-86.25%)
Mutual labels:  package

inview_notifier_list

Build Status pub package

A Flutter package that builds a ListView or CustomScrollView and notifies when the widgets are on screen within a provided area.

Example 1 Example 2 Example 3(Auto-play video)
ezgif com-gif-maker (1) ezgif com-video-to-gif (1) ezgif com-video-to-gif (2)
Example 4(Custom Scroll View)
csv_example

Index

Use-cases

  • To auto-play a video when a user scrolls.

  • To add real-time update listeners from database to the posts/content only within an area visible to the user.

    Note: If you have other use cases please update this section and create a PR.

Installation

Just add the package to your dependencies in the pubspec.yaml file:

dependencies:
  inview_notifier_list: ^1.0.0

Basic Usage

Step 1:

Add the InViewNotifierList to your widget tree

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: InViewNotifierList(
		...
      ),
    );
  }
}

Step 2:

Add the required property isInViewPortCondition to the InViewNotifierList widget. This is the function that defines the area which the widgets overlap should be notified as currently in-view.

typedef bool IsInViewPortCondition(
  double deltaTop,
  double deltaBottom,
  double viewPortDimension,
);

It takes 3 parameters:

  1. deltaTop: It is the distance from top of the widget to be notified in the list view to top of the viewport(0.0).

  2. deltaBottom: It is the distance from bottom of the widget to be notified in the list view to top of the viewport(0.0).

  3. viewPortDimension: The height or width of the viewport depending on the srollDirection property provided. The image below showcases the values if the srollDirection is Axis.vertical.

    Untitled Diagram

Here is an example that returns true only when the widget's top is above the halfway of the viewport and the widget's bottom is below the halfway of the viewport. It is shown in example1.

InViewNotifierList(
  isInViewPortCondition:
      (double deltaTop, double deltaBottom, double viewPortDimension) {
    return deltaTop < (0.5 * viewPortDimension) &&
        deltaBottom > (0.5 * viewPortDimension);
  },
),

step 3:

Add the IndexedWidgetBuilder , which builds the children on demand. It is just like the ListView.builder.

InViewNotifierList(
    isInViewPortCondition:(...){...},
    itemCount: 10,
    builder: (BuildContext context, int index) {
      return child;
    }

),
step 4:

Use the InViewNotifierWidget to get notified if the required widget is currently in-view or not.

The InViewNotifierWidget consists of the following properties:

  1. id: a required String property. This should be unique for every widget that wants to get notified.
  2. builder : Signature for a function that creates a widget for a given index. The function that defines and returns the widget that should be notified as inView. See InViewNotifierWidgetBuilder.
  3. child: The child widget to pass to the builder.
InViewNotifierWidget(
  id: 'unique-Id',
  builder: (BuildContext context, bool isInView, Widget child) {
    return Container(
      child: Text(
        isInView ? 'in view' : 'not in view',
      ),
    );
  },
)

That's it, done!

A complete code:

InViewNotifierList(
  isInViewPortCondition:
      (double deltaTop, double deltaBottom, double vpHeight) {
    return deltaTop < (0.5 * vpHeight) && deltaBottom > (0.5 * vpHeight);
  },
  itemCount: 10,
  builder: (BuildContext context, int index) {
    return InViewNotifierWidget(
      id: '$index',
      builder: (BuildContext context, bool isInView, Widget child) {
        return Container(
          height: 250.0,
          color: isInView ? Colors.green : Colors.red,
          child: Text(
            isInView ? 'Is in view' : 'Not in view',
          ),
        );
      },
    );
  },
);

Run the example app provided and check out the folder for complete code.

Types of Notifiers

  1. InViewNotifierList: builds a ListView and notifies when the widgets are on screen within a provided area.
  2. InViewNotifierCustomScrollView: builds a CustomScrollView and notifies when the widgets are on screen within a provided area.

Properties

  • isInViewPortCondition: [Required] The function that defines the area within which the widgets should be notified as in-view.

  • initialInViewIds: The String list of unique ids of the child widgets that should be initialized as in-view when the list view is built for the first time.

  • contextCacheCount: The number of widget's contexts the InViewNotifierList should stored/cached for the calculations thats needed to be done to check if the widgets are in-view or not. Defaults to 10 and should be greater than 1. This is done to reduce the number of calculations being performed.

    If using a InViewNotifierCustomScrollView with a SliverGrid increase the contextCacheCount to more than number of grid items visible in the screen. See Custom Scroll View example in example folder.

  • endNotificationOffset: The distance from the bottom of the list where the onListEndReached should be invoked. Defaults to the end of the list i.e 0.0.

  • onListEndReached: The function that is invoked when the list scroll reaches the end or the endNotificationOffset if provided.

  • throttleDuration: The duration to be used for throttling the scroll notification. Defaults to 200 milliseconds.

Migration from v0.0.4 to v1.0.0

  • The InViewNotifierList uses an IndexWidgetBuilder instead of the children property just like the ListView.builder. The rest all properties as same as the ListView.builder.

  • Previously you had to add the widget's context and its String id to the InViewState that you want to be notified whether it is in-view or not. Now you can directly make use of the InViewNotifierWidget to get notified if the required widget is currently in-view or not. Check the example provided.

Credits:

Thanks to Didier Boelens for the raw solution.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].