I like your package compared to Freezed. However, I found an issue. Consider the following code
void main(){
final int? someApiResult = null;
final a = Income.empty().copyWith(value: someApiResult); // not null safe here
print(a.value);
}
For the class:
import 'package:app_core/model/app/base_model/updatable_entity.dart';
import 'package:app_core/model/app/custom/income.model.dart';
import 'package:app_core/repository_helper/json_map.dart';
import 'package:app_core/utils/annotations/annotations.dart';
import 'package:copy_with_extension/copy_with_extension.dart';
part 'income.g.dart';
enum IncomeType {
adReward,
couponCode,
refill,
}
@myJsonSerializable
@CopyWith()
class Income {
final int value;
final IncomeType type;
final String incomeSourceId;
Income({
required this.incomeSourceId,
required this.type,
required this.value,
});
factory Income.fromJson(JsonMap json) => _$IncomeFromJson(json);
JsonMap toJson() => _$IncomeToJson(this);
factory Income.empty() => Income(
incomeSourceId: "someID"
value: 0,
type: IncomeType.adReward,
);
}
void main(){
final someApiResult = null;
final a = Income.empty().copyWith(value: someApiResult); // not null safe here
print(a.value);
}
Could you please fix this? The problem is copyWith function parameters is not null safe. The compiler does not report the bug illustrated above. Normally, the developer forgot to write step that handle an edge case when the apiResult is null.
This will leads to unwanted behaviour at runtime. I checked the code. This seems like an easy fix:
Instead of generating code:
Income call({
String? incomeSourceId,
IncomeType? type,
int? value,
});
Can you generate:
Income call({
String incomeSourceId,
IncomeType type,
int value,
});
I like your package compared to Freezed. However, I found an issue. Consider the following code
For the class:
Could you please fix this? The problem is copyWith function parameters is not null safe. The compiler does not report the bug illustrated above. Normally, the developer forgot to write step that handle an edge case when the
apiResult
is null.This will leads to unwanted behaviour at runtime. I checked the code. This seems like an easy fix:
Instead of generating code:
Can you generate: