Code Monkey home page Code Monkey logo

flutter_elastic_list_view's Introduction

ElasticListView

Description

ElasticListView is a drop-in replacement for Flutter’s ListView, enhancing the user experience by dynamically calculating each item’s padding based on the scroll speed, creating an elastic effect. It supports the builder and separated constructors as well as the standard ListView constructor. To migrate to ElasticListView, simply add the Elastic prefix to any existing ListView widget.

ElasticListView Demo

Features

  • Features Elastic Effect: ElasticListView provides an elastic effect to each item by dynamically calculating the padding based on the scroll speed, which is different from the traditional overscroll effect. This makes the list appear as if it’s made of rubber.
  • Drag to Scroll: Adds the drag to scroll behavior by default, providing a smooth scrolling experience. This can be disabled by setting the enableDragScrolling property to false.
  • Optimized Performance: Leverages the performance optimizations of the standard ListView, ensuring excellent performance.

Extended Functionality with Full Compatibility

ElasticListView maintains the exact same properties as the standard ListView, ensuring full compatibility and making it a seamless replacement. In addition, it introduces new properties to control the elastic effect, offering enhanced functionality and customization options beyond the standard ListView.

New Properties

Here are the new properties introduced by ElasticListView:

  • curve: The curve to apply when animating the elastic effect. Defaults to Curves.easeOut.
  • animationDuration: The duration of the elastic effect. Defaults to Duration(milliseconds: 200).
  • enableDragScrolling: Whether to enable drag scrolling. Defaults to true.
  • elasticityFactor: The factor by which the scroll view’s padding changes dynamically based on the scroll speed. Defaults to 4.

Each of these properties allows you to customize the behavior of the elastic effect in ElasticListView.

Usage

To use ElasticListView, simply replace your existing ListView with ElasticListView. All the properties are the same, ensuring full compatibility.

For ListView:

ElasticListView(
  children: <Widget>[
    ListTile(
      leading: Icon(Icons.map),
      title: Text('Map'),
    ),
    ListTile(
      leading: Icon(Icons.photo_album),
      title: Text('Album'),
    ),
    ListTile(
      leading: Icon(Icons.phone),
      title: Text('Phone'),
    ),
  ],
)

For ListView.builder:

ElasticListView.builder(
  itemCount: 10,
  itemBuilder: (context, index) {
    return ListTile(
      title: Text('Item $index'),
    );
  },
)

And for ListView.separated:

ElasticListView.separated(
  itemCount: 10,
  separatorBuilder: (BuildContext context, int index) => Divider(),
  itemBuilder: (BuildContext context, int index) {
    return ListTile(
      title: Text('Item $index'),
    );
  },
)

Contribution

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to create a pull request.

flutter_elastic_list_view's People

Contributors

monster555 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

flutter_elastic_list_view's Issues

When adding a refresh indicator with scroll controller attached to the listview, scroll controller gets disposed and I can't find a way to fix it.

The error is :
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building NotificationListener:
A ScrollController was used after being disposed.
Once you have called dispose() on a ScrollController, it can no longer be used.
The relevant error-causing widget was:
RefreshIndicator RefreshIndicator:file:///Users/ashwinshrestha/development/medhavhi_app/lib/src/class/presentation/paginated_list/view/paginated_list_view.dart:87:53

The code is:

RefreshIndicator.adaptive(
onRefresh: () async =>
_paginationBloc.add(const FetchItems(refresh: true)),
child: ElasticListView(
// controller: _scrollController,
itemCount: state.hasReachedMax
? state.data.length
: state.data.length + 1,
itemBuilder: (context, index) {
return index >= state.data.length
? widget.paginationLoadingWidget ??
SizedBox(
height: 80.v,
width: context.deviceWidth,
child: const Center(
child: CupertinoActivityIndicator(),
),
)
: widget.itemBuilder(context, index, state.data[index]);
},
),
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.