Skip to content

Commit

Permalink
Fix methods generations fields
Browse files Browse the repository at this point in the history
  • Loading branch information
X-SLAYER committed Jan 26, 2024
1 parent 61680fc commit 673ba3f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 37 deletions.
14 changes: 8 additions & 6 deletions src/app/components/Controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function Controls({ onControlChange }) {
useDefaultValue: false,
requiredProperties: false,
useFreezed: false,
useHive: false,
};

const loadSavedSettings = () => {
Expand Down Expand Up @@ -164,21 +165,22 @@ export default function Controls({ onControlChange }) {
/>
<span>
Use{" "}
<span className="font-mono font-bold text-blue-600">
Freezed
</span>
<span className="font-mono font-bold text-blue-600">Freezed</span>
</span>
</label>

<label className="flex items-center space-x-2">
<input
type="checkbox"
className="settings-checkbox"
checked={controls.useDefaultValue}
id="useDefaultValue"
checked={controls.useHive}
id="useHive"
onClick={handleCheckboxChange}
/>
<span>Use default value </span>
<span>
Use{" "}
<span className="font-mono font-bold text-blue-600">HIVE</span>
</span>
</label>

<label className="flex items-center space-x-2">
Expand Down
36 changes: 6 additions & 30 deletions src/app/utils/CustomDartRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
} from "quicktype-core/dist/support/Strings";
import { defined } from "quicktype-core/dist/support/Support";
import { CustomDartOption } from ".";
import { generateDartOptions } from "./Generate_dart_options";
import { generateDartOptions } from "./GeneratDartClass";
export const dartOptions = {
nullSafety: new BooleanOption("null-safety", "Null Safety", true),
justTypes: new BooleanOption("just-types", "Types only", true),
Expand Down Expand Up @@ -735,35 +735,11 @@ export class DartRenderer extends ConvenienceRenderer {
if (maybeNullable === null) {
return dynamic;
}
const type = this.dartType(t, true);
let isAClass = false;
let hasDefaultValue =
!Array.isArray(type) &&
type !== "DateTime" &&
this._options.useDefaultValue;
let defaultValue = null;
if (typeof type == "object") {
let isArray = Array.isArray(type);
isAClass = !isArray && type["kind"] !== "annotated";
}
if (hasDefaultValue) {
defaultValue = this.getDefaultValueForType(type);
}
return isAClass
? [
dynamic,
" == null ? null : ",
this.fromDynamicExpression(maybeNullable, dynamic),
]
: hasDefaultValue
? [
this.fromDynamicExpression(
maybeNullable,
dynamic,
` ?? ${defaultValue}`
),
]
: [this.fromDynamicExpression(maybeNullable, dynamic)];
return this.fromDynamicExpression(
unionType.isNullable,
maybeNullable,
dynamic
);
},
(transformedStringType) => {
switch (transformedStringType.kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const generateDartOptions = (options: CustomDartOption) => {
useHive: new BooleanOption(
"use-hive",
"Generate annotations for Hive type adapters",
false,
options.useHive,
"secondary"
),
useJsonAnnotation: new BooleanOption(
Expand Down
1 change: 1 addition & 0 deletions src/app/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type CustomDartOption = {
finalProperties: boolean;
generateFromJson: boolean;
useFreezed: boolean;
useHive: boolean;
};

export async function runQuickType(
Expand Down

0 comments on commit 673ba3f

Please sign in to comment.