Skip to content

flutter: skip gen Container with empty props - #192

Merged
bernaferrari merged 1 commit into
bernaferrari:refactorfrom
ZeroNetX:skip-empty-container
Mar 18, 2025
Merged

bernaferrari merged 1 commit into
bernaferrari:refactorfrom
ZeroNetX:skip-empty-container

Conversation

@canewsin

@canewsin canewsin commented Mar 9, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@bernaferrari

Copy link
Copy Markdown
Owner

Thanks!!

@canewsin
canewsin force-pushed the skip-empty-container branch from 426d71b to 8bf7096 Compare March 13, 2025 09:48
@bernaferrari

Copy link
Copy Markdown
Owner

It is probably better to do like props =..., then isEmptyProps() else...

@canewsin

Copy link
Copy Markdown
Contributor Author

Extract props to a separate variable? Gotcha

@canewsin
canewsin force-pushed the skip-empty-container branch from 8bf7096 to 4bfcb85 Compare March 15, 2025 04:59
@canewsin

Copy link
Copy Markdown
Contributor Author

@bernaferrari done

@bernaferrari

Copy link
Copy Markdown
Owner

Is empty props working as it should? Because the width/height already check for zero and ignore that. Not sure the difference

@canewsin

Copy link
Copy Markdown
Contributor Author

yup, this function checks all properties and skips if property is default which resulted in unnecessary container.

const hasEmptyProps = (props: Record<string, string>): boolean => {
...
}

currently these props are being checked for default values

properties.width = skipDefaultProperty(width, "0");
properties.height = skipDefaultProperty(height, "0");
properties.padding = propPadding;
properties.clipBehavior = clipBehavior;

const parsedDecoration = skipDefaultProperty(
  propBoxDecoration,
  "BoxDecoration()",
);
properties.decoration = clipBehavior ? propBoxDecoration : parsedDecoration;

const isEmptyProps = hasEmptyProps(properties);

without this check result will be

Before Patch

Container(
	child: Column(
		children: [SomeWidgetsHere()...]
	)
)

After Patch

Column(
	children: [SomeWidgetsHere()...]
)

@bernaferrari
bernaferrari merged commit 8792338 into bernaferrari:refactor Mar 18, 2025
@canewsin
canewsin deleted the skip-empty-container branch March 18, 2025 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants