Add auto* flags to BuildContext
This commit is contained in:
parent
5ccc7755a7
commit
4319721ce3
2 changed files with 16 additions and 6 deletions
|
@ -25,9 +25,17 @@ Future<BuildContext> buildContext(
|
|||
bool autoSnakeCaseNames,
|
||||
bool autoIdAndDateFields,
|
||||
{bool heedExclude: true}) async {
|
||||
// Check for autoIdAndDateFields, autoSnakeCaseNames
|
||||
autoIdAndDateFields =
|
||||
annotation.peek('autoIdAndDateFields')?.boolValue ?? autoIdAndDateFields;
|
||||
autoSnakeCaseNames =
|
||||
annotation.peek('autoSnakeCaseNames')?.boolValue ?? autoSnakeCaseNames;
|
||||
|
||||
var ctx = new BuildContext(annotation,
|
||||
originalClassName: clazz.name,
|
||||
sourceFilename: p.basename(buildStep.inputId.path));
|
||||
sourceFilename: p.basename(buildStep.inputId.path),
|
||||
autoIdAndDateFields: autoIdAndDateFields,
|
||||
autoSnakeCaseNames: autoSnakeCaseNames);
|
||||
var lib = await resolver.libraryFor(buildStep.inputId);
|
||||
List<String> fieldNames = [];
|
||||
|
||||
|
@ -57,10 +65,6 @@ Future<BuildContext> buildContext(
|
|||
}
|
||||
}
|
||||
|
||||
// Check for autoIdAndDateFields, autoSnakeCaseNames
|
||||
autoIdAndDateFields = annotation.peek('autoIdAndDateFields')?.boolValue ?? autoIdAndDateFields;
|
||||
autoSnakeCaseNames = annotation.peek('autoSnakeCaseNames')?.boolValue ?? autoSnakeCaseNames;
|
||||
|
||||
if (autoIdAndDateFields != false) {
|
||||
if (!fieldNames.contains('id')) {
|
||||
var idField =
|
||||
|
|
|
@ -18,6 +18,8 @@ class BuildContext {
|
|||
/// A map of "synthetic" fields, i.e. `id` and `created_at` injected automatically.
|
||||
final Map<String, bool> shimmed = {};
|
||||
|
||||
final bool autoIdAndDateFields, autoSnakeCaseNames;
|
||||
|
||||
final String originalClassName, sourceFilename;
|
||||
|
||||
/// The fields declared on the original class.
|
||||
|
@ -28,7 +30,11 @@ class BuildContext {
|
|||
/// The name of the field that identifies data of this model type.
|
||||
String primaryKeyName = 'id';
|
||||
|
||||
BuildContext(this.annotation, {this.originalClassName, this.sourceFilename});
|
||||
BuildContext(this.annotation,
|
||||
{this.originalClassName,
|
||||
this.sourceFilename,
|
||||
this.autoSnakeCaseNames,
|
||||
this.autoIdAndDateFields});
|
||||
|
||||
/// The name of the generated class.
|
||||
String get modelClassName => originalClassName.startsWith('_')
|
||||
|
|
Loading…
Reference in a new issue