A Flutter widget that renders an infinite list of items using a double-linked list of nodes. This package allows for dynamic, bidirectional infinite scrolling with programmatic control over the viewport and buffer.
- Infinite Scrolling: Supports infinite lists in both directions (up/down).
- Double Linked List: Uses a linked list structure (
next()andprevious()) instead of an index-based list, making it ideal for graph-like data structures or scenarios where index calculation is expensive or impossible. - Dynamic Sizing: Supports items with variable heights.
- Buffer Control: Customizable
minBufferandmaxBufferto manage how many items are kept in memory outside the viewport. - Programmatic Control:
NodeListViewControllerallows jumping to nodes, selecting next/previous items, and refreshing the list. - Selection Tracking: Built-in support for tracking the "selected" or "focused" node.
Add flutter_nodelistview to your pubspec.yaml:
dependencies:
flutter_nodelistview: ^1.0.0Create a class that extends NodeBase. This class represents an item in your list. You must implement next() and previous() to define the structure of your list.
import 'package:flutter/material.dart';
import 'package:flutter_nodelistview/flutter_nodelistview.dart';
class MyNode extends NodeBase<MyNode> {
final String data;
// Linked list pointers
MyNode? _next;
MyNode? _previous;
MyNode(this.data, {MyNode? next, MyNode? previous})
: _next = next,
_previous = previous,
super(GlobalKey()); // Important: Pass a GlobalKey to super
@override
MyNode? next() {
// Return the next node in the list, or create it if it doesn't exist
_next ??= MyNode("Next Data", previous: this);
return _next;
}
@override
MyNode? previous() {
// Return the previous node in the list
_previous ??= MyNode("Previous Data", next: this);
return _previous;
}
}Use NodeListView in your widget tree.
import 'package:flutter_nodelistview/flutter_nodelistview.dart';
class MyInfiniteList extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Start node
MyNode startNode = MyNode("Start");
return Scaffold(
body: NodeListView<MyNode>(
startNode: startNode,
itemBuilder: (context, node, {selected = false}) {
return ListTile(
title: Text(node.data),
selected: selected, // Highlight the currently 'selected' node
);
},
),
);
}
}Use NodeListViewController to programmatically control the list.
final NodeListViewController<MyNode> controller = NodeListViewController<MyNode>();
// ... inside your build method ...
NodeListView<MyNode>(
controller: controller,
// ... other parameters
)
// ... elsewhere ...
controller.selectNext(); // Scroll to next item
controller.selectPrevious(); // Scroll to previous item
controller.jumpTo(someNode); // Jump to a specific node
controller.refreshAllNodePointers(); // Refresh list if structure changesYou can tune the performance and behavior by adjusting the buffer sizes and fallback size.
NodeListView<MyNode>(
minBuffer: 10, // Minimum items to keep in buffer
maxBuffer: 20, // Maximum items to keep before disposing
fallbackSize: 100.0, // Estimated height for items before they are rendered
// ...
)Contributions are welcome! If you find a bug or want to add a feature, please open an issue or submit a pull request.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/my-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin feature/my-feature). - Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.