I have this code and I get the following error: The default value of an optional parameter must be constant. I have searched this problem on the internet, but putting it as constant does not solve the problem, I would like to understand why this happens. This is the code where the error occurs:
part of 'isar_bbdd_repository_cubit.dart';
class IsarBbddRepositoryState extends Equatable{
final IsarBbddRepositoryImpl isarBbddRepositoryImpl;
const IsarBbddRepositoryState({
this.isarBbddRepositoryImpl = IsarBbddRepositoryImpl(IsarBbddDatasourceImpl()) //ERROR
});
copyWith({
IsarBbddRepositoryImpl? isarBbddRepositoryImpl,
}) => IsarBbddRepositoryState(
isarBbddRepositoryImpl: isarBbddRepositoryImpl ?? this.isarBbddRepositoryImpl
);
@override
List<Object?> get props => [isarBbddRepositoryImpl];
}
This is the code for IsarBbddRepositoryImpl:
import 'package:isar/isar.dart';
import 'package:racha_app/domain/datasource/isar_bbdd_datasource.dart';
import 'package:racha_app/domain/repository/isar_bbdd_repository.dart';
class IsarBbddRepositoryImpl extends IsarBbddRepository{
final IsarBbddDatasource datasource;
IsarBbddRepositoryImpl(this.datasource);
@override
Future<void> delete({required Id isarID, required String uuid}) {
return datasource.delete(isarID: isarID, uuid: uuid);
}
This is the IsarBbddDatasourceImpl code (not yet implemented):
import 'package:isar/isar.dart';
import 'package:racha_app/domain/datasource/isar_bbdd_datasource.dart';
class IsarBbddDatasourceImpl extends IsarBbddDatasource{
@override
Future<void> delete({required Id isarID, required String uuid}) {
// TODO: implement delete
throw UnimplementedError();
}
}
I have tried setting the values as constants, but it does not work.