Build fails due to the usage of TypeConverters with optional property, is this a bug? #686
-
I'm trying to make an extendable base entity that contains an The
class DateTimeConverter extends TypeConverter<DateTime, int> {
@override
DateTime decode(int databaseValue) {
return DateTime.fromMillisecondsSinceEpoch(databaseValue);
}
@override
int encode(DateTime value) {
return value.millisecondsSinceEpoch;
}
}
class BaseEntity {
@PrimaryKey(autoGenerate: true)
final int? id;
@ColumnInfo(name: 'created_at')
final DateTime createdAt;
@ColumnInfo(name: 'updated_at')
final DateTime updatedAt;
BaseEntity({
this.id,
DateTime? updatedAt,
DateTime? createdAt,
}) : createdAt = createdAt ?? DateTime.now(),
updatedAt = DateTime.now();
}
@Entity(tableName: 'categories')
class Category extends BaseEntity {
final String name;
@ColumnInfo(name: 'label_color')
final int? labelColor;
Category(
this.name,
this.labelColor, {
int? id,
DateTime? createdAt,
DateTime? updatedAt,
}) : super(id: id, createdAt: createdAt, updatedAt: updatedAt);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Category &&
runtimeType == other.runtimeType &&
id == other.id &&
name == other.name &&
labelColor == other.labelColor &&
createdAt == other.createdAt &&
updatedAt == other.updatedAt;
@override
int get hashCode =>
id.hashCode ^
name.hashCode ^
labelColor.hashCode ^
createdAt.hashCode ^
updatedAt.hashCode;
@override
String toString() {
return 'Category { '
'id: $id, '
'name: $name, '
'labelColor: $labelColor, '
'createdAt: $createdAt, '
'updatedAt: $updatedAt '
'}';
}
} It works fine if I change the type to Because I know those values are unmodifiable by the user, I decided to make it optional to avoid writing However, when I try to rebuild my app, it fails with this error PS D:\Yura\Projs\myapp> flutter packages pub run build_runner build --delete-conflicting-outputs
[INFO] Generating build script...
[INFO] Generating build script completed, took 1.3s
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 186ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 3.3s
[INFO] Running build...
[INFO] 1.0s elapsed, 0/1 actions completed.
[INFO] 2.0s elapsed, 0/1 actions completed.
[INFO] 3.1s elapsed, 0/1 actions completed.
[INFO] 4.3s elapsed, 0/1 actions completed.
[INFO] 5.4s elapsed, 0/1 actions completed.
[INFO] 6.5s elapsed, 0/1 actions completed.
[INFO] 24.3s elapsed, 0/1 actions completed.
[WARNING] No actions completed for 24.3s, waiting on:
- floor_generator:floor_generator on lib/app/data/database.dart
[SEVERE] floor_generator:floor_generator on lib/app/data/database.dart:
Column type is not supported for DateTime?
[INFO] Running build completed, took 25.4s
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 224ms
[SEVERE] Failed after 25.7s
pub finished with exit code 1 Is this a bug? Or I implemented it in a wrong way? If that's the case, what's the possible solution to achieve this requirement? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ah, there is already an open issue about this (#508). Will close the discussion now. |
Beta Was this translation helpful? Give feedback.
Ah, there is already an open issue about this (#508). Will close the discussion now.