-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Add enabled Parameter to Common Layout Widgets for Conditional Wrapping #168365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@fazil-kp |
I want to clarify that my proposal isn’t limited to ExpandedThanks for pointing me to those packages! 🙏 I want to clarify that my proposal isn’t limited to Expanded—I’m envisioning an enabled flag on all the common layout widgets (Center, Padding, SingleChildScrollView, etc.) so that you can conditionally apply any wrapper declaratively:
Why this matters
No more
for every case.
You can drive all layout decisions from a single breakpoint or orientation API, rather than sprinkling if/ternary everywhere.
When you tweak your responsive rules (e.g. breakpoint from 600→720px), you update one helper instead of hunting down dozens of conditional wrappers.
Works for any widget that “wraps” another—think Align, ConstrainedBox, DecoratedBox, even animations or custom decorators. Next stepsIf this sounds useful, I’d be happy to:
|
It probably sounds like a package, but I'll keep the issue open and label for team's tracking. |
Thanks for keeping this open and tagging it! |
Uh oh!
There was an error while loading. Please reload this page.
Use case
Summary
When building responsive UIs in Flutter, we often need to conditionally wrap widgets in Expanded, depending on the screen size—e.g., 📱 mobile vs 🖥 desktop. This pattern quickly leads to repetitive and cluttered layout code, making it harder to read and maintain.
Proposal
Introduce either:
Why This Matters
✅ Clean up widget tree from repeated if or ternary expressions
✅ Avoid deep nesting and improve readability
✅ Write a single layout codebase for mobile and desktop
✅ Encourage reusable, scalable, and composable UI patterns
✅ Helps developers define and use their own responsive logic
Proposal
Example Implementation (Current Workaround)
Here’s a custom SmartExpand widget we currently use to achieve this:
Usage Example:
Suggested Flutter Framework Enhancement
A simpler alternative could be enhancing the Expanded widget itself to support an enabled flag:
When enabled is false, it would simply return child without applying any layout constraints.
The text was updated successfully, but these errors were encountered: