-
-
Notifications
You must be signed in to change notification settings - Fork 286
Closed
Labels
Description
Following documentation and the example provided in this discussion I have the following implementation.
// pagination_options.dart
import 'package:freezed_annotation/freezed_annotation.dart';
part 'pagination_options.freezed.dart';
part 'pagination_options.g.dart';
enum SortDirection {
asc, //ascending
desc //descending
}
@Freezed(makeCollectionsUnmodifiable: false)
abstract class PaginationOptions with _$PaginationOptions {
const PaginationOptions._();
const factory PaginationOptions({
/// Page number to fetch
@Default(1) int page,
/// How many items per page
@Default(20) int limit,
/// Optional search/query string
String? query,
/// Sorting map: key = field name, value = ascending?
@Default({}) Map<String, SortDirection> sort,
/// Optional filters by key/value
@Default({}) Map<String, dynamic> filters,
}) = _PaginationOptions;
factory PaginationOptions.fromJson(Map<String, dynamic> json) =>
_$PaginationOptionsFromJson(json);
}and then
// service_pagination_options.dart
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../../general/api/shared/pagination_options.dart';
part 'service_pagination_options.freezed.dart';
part 'service_pagination_options.g.dart';
@Freezed(makeCollectionsUnmodifiable: false)
abstract class ServicePaginationOptions extends PaginationOptions with _$ServicePaginationOptions {
const ServicePaginationOptions._() : super._();
const factory ServicePaginationOptions({
/// Page number to fetch
@Default(1) int page,
/// How many items per page
@Default(20) int limit,
/// Optional search/query string
String? query,
/// Sorting map: key = field name, value = ascending?
@Default({}) Map<String, SortDirection> sort,
/// Optional filters by key/value
@Default({}) Map<String, dynamic> filters,
/// Keys of the services to **include** in the paginated result.
/// If null, no include filter is applied.
List<String>? keys,
/// Keys of the services to **exclude** from the paginated result.
/// If null, no exclusion filter is applied.
List<String>? excludeKeys,
}) = _ServicePaginationOptions;
factory ServicePaginationOptions.fromJson(Map<String, dynamic> json) =>
_$ServicePaginationOptionsFromJson(json);
}
However i am getting the following errors in service_pagination_options.dart:
'_$ServicePaginationOptions.copyWith' ('$ServicePaginationOptionsCopyWith<ServicePaginationOptions> Function()') isn't a valid override of '_$PaginationOptions.copyWith' ('$PaginationOptionsCopyWith<PaginationOptions> Function()'). (Documentation)
The member being overridden (pagination_options.freezed.dart:28).
The class 'PaginationOptions' doesn't have a constructor named '_'. (Documentation)
Try defining a constructor named '_' in 'PaginationOptions', or invoking a different constructor.
I am using freezed: ^3.2.3 and am on flutter 3.38.2.