Generator not building file for Freezed class
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Steps to Reproduce**
We use Hive for our settings and we have it attached to a Freezed class as well. We are on the most recent version of both platforms. The freezer generator file builds without fail but the hive file does not. Actually, it only will build if I add or remove the 'abstract' keyword. Once I change the 'abstract' (either adding or removing it) it will build the generator file BUT the next time the generator runs it will remove the file again and I will have to change it again to trigger a rebuild.
``
**Code sample**
```
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:../domain/settings/settings.dart';
part 'settings_dto.freezed.dart';
part 'settings_dto.g.dart';
@freezed
class SettingsDto with _$SettingsDto {
@HiveType(typeId: 1, adapterName: 'SettingsDtoAdapter')
const SettingsDto._();
@HiveType(typeId: 0)
const factory SettingsDto({
@HiveField(0) final String? id,
@HiveField(1) final String? units,
}) = _SettingsDto;
factory SettingsDto.fromDomain(Settings settings) {
return SettingsDto(
id: settings.id,
units: settings.units.name,
);
}
Units stringToEnumUnits(String unitsStr) {
Units u =
Units.values.firstWhere((e) => e.toString() == 'Units.' + unitsStr);
return u;
}
Settings toDomain() => Settings(
id: id,
units: units == null ? Units.imperial : stringToEnumUnits(units!),
);
}
```
**Version**
- Flutter version: version 2.7<3.0 (haven't tested it on 3 yet)
- Hive version: hive: ^2.2.1
hive_flutter: ^1.1.0
hive_generator: ^1.1.3
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.