- Fixes `FixedSizeList` to take a generic `T` type, rather than
explicitly a `String`
This commit is contained in:
2025-05-16 13:08:39 +02:00
parent 363fb20665
commit 176efdf458
3 changed files with 10 additions and 6 deletions
+4
View File
@@ -1,3 +1,7 @@
## 1.4.3
- [FIX] Ensure that `FixedSizeList` takes any type of object.
## 1.4.2
- Added the `isLeapYear` extension to the `DateTime` and `int` objects.
+5 -5
View File
@@ -2,20 +2,20 @@
///
/// When a new element is added and the list reaches its maximum capacity,
/// the oldest element in the list is automatically removed to make space.
class FixedSizeList {
class FixedSizeList<T> {
final int _capacity;
final List<String> _list;
final List<T?> _list;
/// Creates a [FixedSizeList] with the specified [capacity].
///
/// The initial list will be empty.
FixedSizeList(this._capacity) : _list = <String>[];
FixedSizeList(this._capacity) : _list = <T?>[];
/// Adds a new [element] to the list.
///
/// If the list is already at its maximum [capacity], the oldest element
/// will be removed before the new [element] is added.
void add(String element) {
void add(T? element) {
_list.add(element);
if (_list.length > _capacity) {
_list.removeAt(0);
@@ -25,5 +25,5 @@ class FixedSizeList {
/// Returns an unmodifiable view of the current items in the list.
///
/// This prevents external modification of the internal list.
List<String> get items => List.unmodifiable(_list);
List<T?> get items => List.unmodifiable(_list);
}
+1 -1
View File
@@ -1,7 +1,7 @@
name: arcane_helper_utils
description: Provides a variety of helpful utilities and extensions for Flutter
and Dart.
version: 1.4.2
version: 1.4.3
repository: https://github.com/hanskokx/arcane_helper_utils
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues