zeba_academy_list_utils 1.0.0
zeba_academy_list_utils: ^1.0.0 copied to clipboard
Generic list helper utilities for Dart and Flutter including chunking, partitioning, distinct values, flattening, safe indexing, rotation, and moving items.
zeba_academy_list_utils #
A lightweight, type-safe collection of generic list utilities for Dart and Flutter.
zeba_academy_list_utils provides convenient helpers for common list operations such as chunking, partitioning, distinct values, flattening, safe indexing, rotating, and moving items.
No external runtime dependencies. No platform-specific code. Just simple, reusable Dart utilities.
โจ Features #
- ๐ฆ Chunk lists into fixed-size groups
- ๐ Partition lists into matching and non-matching values
- ๐งน Remove duplicate values
- ๐ Distinct by key for custom objects
- ๐ Flatten nested iterables
- ๐ก๏ธ Safe list indexing without
RangeError - โฉ๏ธ Rotate lists left
- โช๏ธ Rotate lists right
- ๐ Move items between positions
- โฌ๏ธ Move items to the beginning
- โฌ๏ธ Move items to the end
- ๐งฉ Fully generic and type-safe
- ๐ชถ Lightweight and dependency-free
- ๐ Null-safe
- ๐ Well-documented API
- ๐งช Comprehensive unit tests
๐ฆ Installation #
Add zeba_academy_list_utils to your pubspec.yaml:
dependencies:
zeba_academy_list_utils: ^1.0.0
Then run:
flutter pub get
For a pure Dart project:
dart pub get
๐ Quick Start #
Import the package:
import 'package:zeba_academy_list_utils/zeba_academy_list_utils.dart';
You can then use:
final chunks = ZebaListUtils.chunk(
[1, 2, 3, 4, 5],
2,
);
print(chunks);
// [[1, 2], [3, 4], [5]]
๐ API Reference #
chunk() #
Splits an iterable into groups containing at most the specified number of elements.
final result = ZebaListUtils.chunk(
[1, 2, 3, 4, 5],
2,
);
print(result);
Output:
[[1, 2], [3, 4], [5]]
Invalid size #
The size must be greater than zero.
ZebaListUtils.chunk(
[1, 2, 3],
0,
);
Throws:
ArgumentError
partition() #
Splits values into two lists:
- Values matching the predicate
- Values not matching the predicate
final result = ZebaListUtils.partition(
[1, 2, 3, 4, 5],
(value) => value.isEven,
);
print(result);
Output:
[[2, 4], [1, 3, 5]]
distinct() #
Removes duplicate values while preserving the order of their first occurrence.
final result = ZebaListUtils.distinct(
[1, 2, 2, 3, 1, 4],
);
print(result);
Output:
[1, 2, 3, 4]
Works with strings as well:
final result = ZebaListUtils.distinct(
['Flutter', 'Dart', 'Flutter', 'Firebase'],
);
print(result);
Output:
[Flutter, Dart, Firebase]
distinctBy() #
Removes duplicates based on a selected key.
This is particularly useful with model objects.
final users = [
User(id: 1, name: 'Sarvesh'),
User(id: 2, name: 'Arun'),
User(id: 1, name: 'Another User'),
];
final uniqueUsers = ZebaListUtils.distinctBy(
users,
(user) => user.id,
);
The first object for each unique key is preserved.
flatten() #
Flattens one level of nested iterables.
final result = ZebaListUtils.flatten<int>(
[
[1, 2],
[3, 4],
[5, 6],
],
);
print(result);
Output:
[1, 2, 3, 4, 5, 6]
It also works with other iterable types:
final result = ZebaListUtils.flatten<String>(
[
{'A', 'B'},
{'C', 'D'},
],
);
elementAtOrNull() #
Safely accesses an element by index.
Instead of:
final value = items[10];
which may throw a RangeError, use:
final value = ZebaListUtils.elementAtOrNull(
items,
10,
);
If the index is invalid:
null
Example:
final numbers = [10, 20, 30];
print(
ZebaListUtils.elementAtOrNull(numbers, 1),
);
// 20
print(
ZebaListUtils.elementAtOrNull(numbers, 10),
);
// null
Negative indexes are also handled safely:
final value = ZebaListUtils.elementAtOrNull(
[1, 2, 3],
-1,
);
print(value);
// null
โฉ๏ธ rotateLeft() #
Rotates list elements to the left.
final result = ZebaListUtils.rotateLeft(
[1, 2, 3, 4, 5],
2,
);
print(result);
Output:
[3, 4, 5, 1, 2]
The original list is not modified.
Large rotation values #
final result = ZebaListUtils.rotateLeft(
[1, 2, 3],
4,
);
print(result);
Output:
[2, 3, 1]
The number of steps is automatically normalized.
โช๏ธ rotateRight() #
Rotates list elements to the right.
final result = ZebaListUtils.rotateRight(
[1, 2, 3, 4, 5],
2,
);
print(result);
Output:
[4, 5, 1, 2, 3]
The original list is not modified.
๐ move() #
Moves an element from one index to another.
final result = ZebaListUtils.move(
['A', 'B', 'C', 'D'],
0,
2,
);
print(result);
Output:
[B, C, A, D]
Moving backwards #
final result = ZebaListUtils.move(
['A', 'B', 'C', 'D'],
3,
1,
);
print(result);
Output:
[A, D, B, C]
The original list remains unchanged.
โฌ๏ธ moveToStart() #
Moves an element to index 0.
final result = ZebaListUtils.moveToStart(
['A', 'B', 'C', 'D'],
2,
);
print(result);
Output:
[C, A, B, D]
โฌ๏ธ moveToEnd() #
Moves an element to the last position.
final result = ZebaListUtils.moveToEnd(
['A', 'B', 'C', 'D'],
1,
);
print(result);
Output:
[A, C, D, B]
๐งฉ Generic Type Support #
The package is designed around Dart generics.
It works with integers:
final numbers = ZebaListUtils.distinct(
[1, 2, 2, 3],
);
Strings:
final names = ZebaListUtils.distinct(
['A', 'B', 'A'],
);
Custom classes:
final products = ZebaListUtils.distinctBy(
productList,
(product) => product.id,
);
And other Dart types:
final dates = ZebaListUtils.distinct(
dateList,
);
๐ Immutability #
Operations that transform a list return a new list rather than modifying the original list.
For example:
final original = ['A', 'B', 'C'];
final result = ZebaListUtils.move(
original,
0,
2,
);
print(original);
// [A, B, C]
print(result);
// [B, C, A]
This makes the utilities suitable for state-management approaches where immutable state updates are preferred.
๐งช Testing #
Run the complete test suite:
flutter test
Or:
dart test
Format the package:
dart format lib test
Analyze the package:
flutter analyze
Before publishing:
flutter pub publish --dry-run
๐ Project Structure #
zeba_academy_list_utils/
โ
โโโ lib/
โ โโโ src/
โ โ โโโ zeba_list_utils.dart
โ โ
โ โโโ zeba_academy_list_utils.dart
โ
โโโ test/
โ โโโ zeba_academy_list_utils_test.dart
โ
โโโ analysis_options.yaml
โโโ CHANGELOG.md
โโโ LICENSE
โโโ README.md
โโโ pubspec.yaml
๐ฏ Use Cases #
zeba_academy_list_utils can be useful for:
- Flutter UI list manipulation
- Pagination preparation
- Grid data preparation
- Batch processing
- Search result processing
- Removing duplicate records
- Categorizing data
- Reordering lists
- Drag-and-drop list interfaces
- State management
- Data transformation
- Collection preprocessing
- Model list manipulation
๐ก Example: Preparing Grid Data #
final products = [
'Product 1',
'Product 2',
'Product 3',
'Product 4',
'Product 5',
'Product 6',
];
final rows = ZebaListUtils.chunk(
products,
2,
);
for (final row in rows) {
print(row);
}
Output:
[Product 1, Product 2]
[Product 3, Product 4]
[Product 5, Product 6]
๐ก Example: Separating Active and Inactive Items #
final result = ZebaListUtils.partition(
users,
(user) => user.isActive,
);
final activeUsers = result[0];
final inactiveUsers = result[1];
๐ก Example: Reordering Items #
This can be useful when implementing custom list reordering:
final reordered = ZebaListUtils.move(
items,
oldIndex,
newIndex,
);
The original collection remains untouched.
โก Design Principles #
This package follows a few simple principles:
Simple #
APIs should be easy to understand and remember.
Generic #
Utilities should work with any suitable Dart type.
Dependency-free #
The package has no runtime dependencies.
Safe #
Operations validate indexes and invalid arguments where appropriate.
Predictable #
Transformation utilities return new lists rather than unexpectedly mutating existing data.
Flutter-friendly #
The package can be used with any Flutter state-management architecture.
๐ API Overview #
| API | Description |
|---|---|
chunk() |
Splits items into fixed-size groups |
partition() |
Separates items using a predicate |
distinct() |
Removes duplicate values |
distinctBy() |
Removes duplicates using a key |
flatten() |
Flattens one level of nested iterables |
elementAtOrNull() |
Safely accesses an item by index |
rotateLeft() |
Rotates items to the left |
rotateRight() |
Rotates items to the right |
move() |
Moves an item between indexes |
moveToStart() |
Moves an item to the first position |
moveToEnd() |
Moves an item to the final position |
๐ ๏ธ Requirements #
- Dart SDK:
^3.12.0 - Flutter: Compatible with modern Flutter releases
The package does not require:
- Firebase
- REST APIs
- Native plugins
- External services
- Code generation
- Build runners
- Runtime dependencies
๐ค Contributing #
Contributions are welcome.
If you find a bug or have an improvement:
- Fork the repository.
- Create a feature branch.
- Add or update tests.
- Run formatting.
- Run static analysis.
- Run the complete test suite.
- Submit a pull request.
Example:
dart format lib test
flutter analyze
flutter test
Please keep contributions focused, documented, and covered by tests.
๐ Issues #
If you encounter a bug or have a feature request, please open an issue in the project's GitHub repository.
When reporting a bug, include:
- Dart version
- Flutter version
- Package version
- Minimal reproduction
- Expected behavior
- Actual behavior
๐ License #
Copyright ยฉ 2026 Zeba Academy.
This project is licensed under the GNU General Public License v3.0 (GPL-3.0).
You may use, study, modify, and redistribute this software according to the terms of the GPL-3.0 license.
See the LICENSE file for the complete license text.
For the full license terms, visit:
https://www.gnu.org/licenses/gpl-3.0.html
๐จโ๐ป About Me #
โจ Iโm Sufyan bin Uzayr, an open-source developer passionate about building and sharing meaningful projects.
You can learn more about me and my work at:
or connect with me on LinkedIn:
https://www.linkedin.com/in/sufyanism
๐ Your All-in-One Learning Hub! #
๐ Explore courses and resources in coding, tech, and development at Zeba Academy.
Empower yourself with practical skills through curated tutorials, real-world projects, and hands-on experience. Level up your tech game today! ๐ปโจ
Zeba Academy is a learning platform dedicated to coding, technology, and development.
โก๏ธ Visit our main site:
โก๏ธ Explore hands-on courses and resources:
โก๏ธ Check out our YouTube channel for more tutorials:
https://www.youtube.com/@zeba.academy
โก๏ธ Follow Zeba Academy on Instagram:
https://www.instagram.com/zeba.academy/
โญ Support the Project #
If you find zeba_academy_list_utils useful:
- โญ Star the repository
- ๐ฆ Use the package in your Flutter/Dart projects
- ๐ Report issues
- ๐ก Suggest improvements
- ๐ค Contribute to the project
- ๐ข Share it with other Dart and Flutter developers
Every contribution helps make the project better.
โค๏ธ Thank You #
Thank you for visiting zeba_academy_list_utils.
Built with โค๏ธ for the Dart and Flutter community by Zeba Academy.
Keep learning. Keep building. Keep sharing. ๐