This guide explains the major changes in version 4 provides step-by-step instructions to update your code.
- Centralized Logic:
v4 introduces aBasePaginator<T>
class that centralizes shared logic such as debouncing and disposal checks.
Action:- If you previously subclassed
Paginator
directly, consider extending eitherBasePaginator<T>
or the newPaginator<T>
. - Override the
onPageChanged
method if you need custom behavior on page transitions. This replaces any older custom hooking mechanisms aroundgoToPage
.
- If you previously subclassed
- Transformation Methods:
Earlier versions might have returned raw lists or used a different caching mechanism for methods likewhere()
orsort()
.
Action:- In v4, these methods now return fully instantiated
Paginator<T>
objects, stored internally in a time-based_transformCache
. - Update your code to work with the returned
Paginator<T>
instances instead of accessing raw transformation results.
- In v4, these methods now return fully instantiated
- Avoid Overlapping Requests:
The new implementation usesCancelableOperation
to deduplicate and cancel overlapping fetch requests.
Action:- Set
autoCancelFetches
totrue
in yourPaginationConfig
if you want to prevent concurrent fetches. - If you prefer the old behavior (allowing multiple simultaneous requests), set
autoCancelFetches
tofalse
.
- Set
- Unified Infinite Scrolling:
TheInfinitePaginator
now supports both page-based and cursor-based approaches via factory constructors.
Action:- Replace any legacy infinite scroll classes or custom implementations with either
InfinitePaginator.pageBased()
orInfinitePaginator.cursorBased()
. - Adapt any direct usage of pagination keys to match the new factory constructor signatures.
- Replace any legacy infinite scroll classes or custom implementations with either
-
Specific Duration Methods:
The genericdelay()
method has been replaced by more specific duration-based delay methods.Action: Replace old delay methods as follows:
- Replace await
2.delay();
andawait 2.secDelay;
withawait 2.secondsDelay();
- Replace await
5.minDelay;
withawait 5.minutesDelay();
- Replace await
1.daysDelay;
withawait 1.daysDelay();
- And so on for other time units.
Additionally, if you previously used a delay with a callback:
// Old: await 2.delay(() => someFunction()); // New: final result = await 2.secondsDelay(() => someFunction());
- Replace await
-
Tracking Metrics:
If you need to track metrics (such as page loads, errors, and cache hits), add thePaginationAnalytics
mixin to your custom paginator class.Action: Incorporate the mixin where needed to log metrics according to your application requirements.
-
No-Op After Disposal:
In v4, methods such asgoToPage
are designed to be no-ops (instead of throwing exceptions) after the paginator is disposed. This ensures that lifecycle streams remain silent post-disposal.Action:
- Update your tests to reflect this behavior.
- If your code previously expected an exception after disposal, refactor it to handle no-ops instead.
-
Review Your Tests:
Confirm that your existing tests pass. Update any tests that reference legacy method names, class hierarchies, or disposal behavior.
-
String Extensions:
- Removed deprecated
toDateTime
method - Use
toDateFormatted
ortoDate
instead
- Removed deprecated
-
DateTime Extensions:
- Removed deprecated
format
method - Use
formatted
instead - Added stricter type checking for date operations
- Removed deprecated
-
try/toDateWithFormat
renamed totry/toDateFormatted
:- Action: Update all instances of
try/toDateWithFormat
in your code totry/toDateFormatted
.
- Action: Update all instances of
-
dateFormat
on String is now a method with an optionallocale
parameter: This change gives you more control over the formatting process, allowing you to specify the locale explicitly for accurate results.- Old Usage:
String formattedDate = '2024-06-10'.dateFormat; // Used default or current locale
- New Usage:
String formattedDate = '2024-06-10'.dateFormat(); // Uses default locale String formattedDateUS = '2024-06-10'.dateFormat('en_US'); // Explicitly uses US locale
- Old Usage:
These methods now have an optional startOfWeek
parameter to customize the first day of the week. The default value is
DateTime.monday
.
Old Usage:
DateTime now = DateTime.now();
DateTime firstDayOfWeek = now.firstDayOfWeek;
DateTime lastDayOfWeek = now.lastDayOfWeek;
New Usage:
DateTime now = DateTime.now();
DateTime firstDayOfWeek = now.firstDayOfWeek(); // Defaults to Monday
DateTime lastDayOfWeek = now.lastDayOfWeek(); // Defaults to Monday
// Customize start of week (e.g., Sunday)
DateTime firstDayOfWeekSunday = now.firstDayOfWeek(startOfWeek: DateTime.sunday);
flatJson
renamed toflatMap
: If you were using theflatJson
method onMap<String, dynamic>
, update your code to useflatMap
instead. The functionality has been enhanced to handle arrays, circular references, and provide an option to exclude arrays.makeEncodable
andsafelyEncodedJson
renamed: ThemakeEncodable
andsafelyEncodedJson
methods onMap<K, V>
have been renamed toencodableCopy
andencodedJsonString
, respectively. Additionally, an issue where sets were not correctly converted to JSON-encodable lists has been fixed.
Review the changelog for any other minor breaking changes and update your code accordingly.
If you encounter any issues during the migration process please fill an issue here.