zeba_academy_sorting 1.0.0
zeba_academy_sorting: ^1.0.0 copied to clipboard
A lightweight Flutter package for ascending, descending, multi-field, and custom comparator sorting.
zeba_academy_sorting #
A lightweight, dependency-free Flutter and Dart package for sorting collections with ease. It provides ascending and descending sorting, multi-field sorting, custom comparators, immutable sorting, in-place sorting, and convenient extension methods.
✨ Features #
- ✅ Ascending sorting
- ✅ Descending sorting
- ✅ Multi-field sorting
- ✅ Custom comparator support
- ✅ Generic type support
- ✅ Sort numbers, strings, booleans, and DateTime values
- ✅ Null-safe implementation
- ✅ Immutable sorting (returns a new list)
- ✅ In-place sorting
- ✅ Extension methods for clean code
- ✅ Lightweight and dependency-free
- ✅ Flutter and pure Dart compatible
Installation #
Add the package to your pubspec.yaml.
dependencies:
zeba_academy_sorting: ^1.0.0
Then run:
flutter pub get
Import #
import 'package:zeba_academy_sorting/zeba_academy_sorting.dart';
Basic Example #
final numbers = [5, 1, 8, 2, 3];
final sorted = Sorting.ascending(
numbers,
(e) => e,
);
print(sorted);
// Output:
// [1,2,3,5,8]
Ascending Sorting #
final students = [
Student("John", 21),
Student("Alice", 19),
Student("David", 22),
];
final result = Sorting.ascending(
students,
(e) => e.age,
);
Descending Sorting #
final result = Sorting.descending(
students,
(e) => e.age,
);
Sort Strings #
final names = [
"Charlie",
"Alice",
"Bob",
];
final sorted = Sorting.ascending(
names,
(e) => e,
);
Sort Numbers #
final prices = [
99,
35,
150,
42,
];
final sorted = Sorting.descending(
prices,
(e) => e,
);
Sort DateTime #
final dates = [
DateTime(2025, 5, 10),
DateTime(2023, 8, 15),
DateTime(2024, 1, 1),
];
final sorted = Sorting.ascending(
dates,
(e) => e,
);
Multi-field Sorting #
final result = students.sortByFields([
SortField<Student>(
selector: (e) => e.age,
),
SortField<Student>(
selector: (e) => e.marks,
order: SortOrder.descending,
),
]);
The list is first sorted by age and then by marks in descending order when ages are equal.
In-place Sorting #
students.sortSelf(
(e) => e.name,
);
Immutable Sorting #
final sorted = students.sortAscending(
(e) => e.name,
);
The original list remains unchanged.
Custom Comparator #
final list = [...students];
list.sort(
(a, b) => b.name.compareTo(a.name),
);
Extension Methods #
students.sortAscending(
(e) => e.age,
);
students.sortDescending(
(e) => e.salary,
);
students.sortByFields([
SortField<Student>(
selector: (e) => e.department,
),
SortField<Student>(
selector: (e) => e.salary,
order: SortOrder.descending,
),
]);
students.sortSelf(
(e) => e.name,
);
API Overview #
Sorting #
| Method | Description |
|---|---|
Sorting.ascending() |
Returns a new ascending sorted list |
Sorting.descending() |
Returns a new descending sorted list |
Sorting.sortInPlace() |
Sorts the original list |
MultiSorter #
| Method | Description |
|---|---|
MultiSorter.sort() |
Sort using multiple fields |
SortField #
Represents one sorting rule.
SortField<Student>(
selector: (e) => e.age,
order: SortOrder.ascending,
);
ComparatorBuilder #
Create reusable comparators.
final comparator = ComparatorBuilder.by<Student>(
(e) => e.age,
);
students.sort(comparator);
Why zeba_academy_sorting? #
- Clean API
- Strongly typed
- Easy to use
- Highly reusable
- Generic implementation
- Zero runtime dependencies
- Supports Flutter and Dart
- Production-ready
- Fully null-safe
Platform Support #
| Platform | Supported |
|---|---|
| Android | ✅ |
| iOS | ✅ |
| Web | ✅ |
| Windows | ✅ |
| macOS | ✅ |
| Linux | ✅ |
Roadmap #
Future releases may include:
- Stable sorting algorithms
- Natural string sorting
- Locale-aware string comparison
- Nested property sorting
- Collection utility helpers
- Performance optimizations
- Additional comparator builders
Contributing #
Contributions, feature requests, bug reports, and pull requests are welcome.
If you discover an issue or have an idea for improvement, feel free to open an issue or submit a pull request.
License #
This project is licensed under the GNU General Public License v3.0 (GPL-3.0).
See the LICENSE file for complete license information.
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 https://sufyanism.com/ or connect with me on LinkedIn at https://www.linkedin.com/in/sufyanism.
Your all-in-one learning hub! #
🚀 Explore courses and resources in coding, tech, and development at Zeba Academy and Code Zeba Academy. Empower yourself with practical skills through curated tutorials, real-world projects, and hands-on experience.
Zeba Academy is a learning platform dedicated to coding, technology, and development.
- 🌐 Main Website: https://zeba.academy
- 💻 Courses & Resources: https://code.zeba.academy
- 📺 YouTube: https://www.youtube.com/@zeba.academy
- 📸 Instagram: https://www.instagram.com/zeba.academy/
Support #
If you find this package useful, consider:
- ⭐ Starring the repository
- 👍 Liking and sharing the project
- 🐞 Reporting issues
- 💡 Suggesting new features
- 🤝 Contributing improvements
Your support helps make open-source software better for everyone.
Thank you for visiting! ❤️