Anchor scroll view - A ScrollController which supports anchor for flutter

Overview

flutter anchor_scroll_controller

This package implement a ScrollController which supports anchor. That is, AnchorScrollController supports to scroll to index and listen to index changed while scrolling by user.

Pub

Features

  • Scroll to index

    Screenshot

  • Listen to index changed

    Screenshot

Getting Started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  anchor_scroll_view: <latest_version>

In your library add the following import:

import 'package:anchor_scroll_controller/anchor_scroll_controller.dart';
import 'package:anchor_scroll_controller/anchor_scroll_wrapper.dart';

Initialize an AnchorScrollController object and use it as the ScrollController of ListView, and wrap the items in the ListView with AnchorItemWrapper

late final AnchorScrollController _scrollController;

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

  _scrollController = AnchorScrollController(
    onIndexChanged: (index) {
      _tabController?.animateTo(index);
    },
  );
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text("GeneralScrollViewWidget"),
    ),
    body: Column(
      children: [
        Expanded(
          child: ListView.builder(
            controller: _scrollController,
            itemCount: length,
            itemBuilder: (context, index) => AnchorItemWrapper(
              key: ValueKey(index),
              index: index,
              controller: _scrollController,
              child: Container(
                height: 50.0 + Random().nextInt(50),
                color: Colors.primaries[index % Colors.primaries.length],
                alignment: Alignment.center,
                child: Text(index.toString(),
                            style: const TextStyle(fontSize: 24, color: Colors.black)),
              ),
            )
          ),
        ),
        ... // omit more code
      ],
    )
  );
  
  ...
  // call AnchorScrollController.scrollToIndex() to scroll to the target index item
  _scrollController.scrollToIndex(index);
  ...
You might also like...

A loading more list which supports ListView,GridView,WaterfallFlow and Slivers.

loading_more_list A loading more list which supports ListView,GridView,WaterfallFlow and Slivers. Language: English | 中文简体 Web demo for LoadingMoreLis

Dec 19, 2022

A page transition which supports drag-down-to-pop gesture.

drag_down_to_pop A page transition which supports drag-down-to-pop gesture. The main source code is copied from the cupertino/route.dart in Flutter SD

Aug 6, 2022

One Page Scroll package for Flutter Web

OPscroll_web OPScroll A simple and easy to use library that creates OnePage sites for Flutter Web Developers! Make a beautiful and smooth landing page

Dec 17, 2022

Code for the "That's how we scroll in Flutter" workshop

flutter_custom_scroll A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

Nov 11, 2022

Flutter Bidirectional ListView - ListView with items that can be scrolled in both directions with a fixed item count and scroll boundaries.

Flutter Bidirectional ListView - ListView with items that can be scrolled in both directions with a fixed item count and scroll boundaries.

Flutter Bidirectional ListView ListView with items that can be scrolled and lazy loaded in up and down direction with a fixed item count and scroll bo

May 30, 2022

FLUTTER API: It's powerful navigation by gestures and taps. You can scroll from left to right or tap on the navigation icons.

FLUTTER API: It's powerful navigation by gestures and taps. You can scroll from left to right or tap on the navigation icons.

scroll_navigation My other APIs Video Viewer Video Editor Helpers Features Fancy animations. Customizable colors. Works with the back button. Scrollin

Jun 14, 2022

Flutter Tutorial - Scroll To Top In ListView

Flutter Tutorial - Scroll To Top In ListView

Flutter Tutorial - Scroll To Top In ListView Let's use Flutter to scroll to the top of a ListView and to detect the current ListView Scroll Position.

Apr 20, 2022

This package allows you to scroll/select the value directly from the dropdown with less effort and time.

Direct Select This package allows you to scroll/select the value directly from the dropdown with less effort and time. Inspired by Virgil Pana shot Sa

Nov 25, 2022

Add a fading effect when the user can scroll.

Add a fading effect when the user can scroll. Demo Quickstart Add the dependency to fading_scroll to your pubspec.yaml file. flutter pub add clickup_f

Dec 14, 2022
Comments
  • [Bug] onIndexChanged doesn't get called on scrollToIndex

    [Bug] onIndexChanged doesn't get called on scrollToIndex

    Bug report

    When using scrollToIndex to change the scroll offset, it seems that onIndexChanged is not called.

    Expected behaviour

    onIndexChanged gets called regardless of how the index is changed

    Actual behaviour

    onIndexChanged is only called when manually scrolling

    Setup

    Version: anchor_scroll_controller: ^0.2.0 SDK constraints: sdk: ">=2.15.1 <3.0.0" Flutter version: stable, 2.8.1 Platform: web OS: windows

    bug 
    opened by clragon 8
  • Add anchorOffset parameter

    Add anchorOffset parameter

    Context: In the app we're writing we have a fake second header that appears after the user scrolls. Since we use a stack to display that second header, it looks like the app scrolls to low (see video below) because the AnchorScrollController doesn't take it into account (which is normal).

    https://user-images.githubusercontent.com/23281436/173837566-00d33f82-c3ed-40f3-b5e3-f82f9f88a507.mp4

    To fix this I added a new optional parameter that will add some offset to the scroll, so that the title can appear below the header as expected.

    https://user-images.githubusercontent.com/23281436/173837602-83beea41-6d07-4b14-97ae-3e583b729907.mp4

    opened by a1r93 2
  • fix an issue that `_currIndex` may be set incorrectly

    fix an issue that `_currIndex` may be set incorrectly

    When scrollToIndex() is called to scroll to an item that isn't in viewport, the scrolling may stop at the top or bottom of the list because the target item hasn't been loaded. Then _currIndex will be set to the target index incorrectly. It may cause some notifications about index change to be ignored. notifyIndexChanged() can set _currIndex to the correct index.

    opened by orzogc 0
  • Please implement jumpTo(index) method

    Please implement jumpTo(index) method

    The scrollTo method is doing fine, but I have a very large list and it has about 4000 items and it takes forever to scroll. also, the height of the items is dynamic so I can't use jumpTo(value) method. so is there any way that I can use jumpTo(index)?

    opened by ahmedtanjim 0
Releases(v0.4.1)
Owner
Lucian
Lucian
The solution allows anchors to compete with each other and co-anchor with viewers in real time

The solution allows anchors to compete with each other and co-anchor with viewers in real time, with a global end-to-end latency of below 300 ms on average, and supports 1080p resolution.

LiteAVSDK 10 Dec 29, 2022
Flutter list view - An unofficial list view for flutter

Flutter List View I don't like official list view. There are some features don't

null 24 Dec 15, 2022
Grid-View-App - Grid View App For Flutter

grid_view_app practice purpose flutter application Getting Started This project

Md Tarequl Islam 4 Jun 9, 2022
Swipeable button view - Create Ripple Animated Pages With Swipeable Button View

swipeable_button_view You can create ripple animated pages with swipeable_button

cemreonur 3 Apr 22, 2022
-UNDER DEVELOPMENT- a project built demonstrating model view view model architecture

mvvm_project A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Atuoha Anthony 4 Nov 28, 2022
A customizable carousel slider widget in Flutter which supports inifinte scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.

flutter_carousel_widget A customizable carousel slider widget in Flutter. Features Infinite Scroll Custom Child Widget Auto Play Horizontal and Vertic

NIKHIL RAJPUT 7 Nov 26, 2022
Todo is an Simple Task Management App coded using Dart which is a peogramming language for Flutter SDK(2.5) supports Null Safety 📑🚩

Todo ?? ?? ?? Introduction Todo is an Simple Task Management App coded using Dart which is a peogramming language for Flutter SDK(2.5) supports Null S

navee-ramesh 6 Nov 5, 2022
This is the code for the POAPin app, which is written in Flutter and currently supports iOS, Android, and Web platforms.

POAPin This is the code for the POAPin app, which is written in Flutter and currently supports iOS, Android, and Web platforms. ?? Get the app Platfor

Glory Lab 17 Nov 7, 2022
A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.

dio_http A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout

null 46 Dec 19, 2021
A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.

Language: English | 中文简体 dio A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File

Flutter中国开源项目 11.2k Jan 3, 2023