Skip to content
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

Form widget is wider than its parent. #45183

Closed
kendalharland opened this issue Nov 19, 2019 · 3 comments
Closed

Form widget is wider than its parent. #45183

kendalharland opened this issue Nov 19, 2019 · 3 comments
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Comments

@kendalharland
Copy link

Create a widget with a Form descendant.

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 500,
      child: MyForm(),
    );
  }
}

class MyForm extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Form(
      child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            TextFormField(
              decoration: const InputDecoration(
                labelText: 'label',
                hintText: 'hint',
              ),
            ),
          ]),
    );
  }
}

I expected that MyForm and MyForm > Form will be no wider than 500px. In reality both widgets expand to fill the width of the entire screen.

The only way I've found to limit the size of a form is by putting it in a Flex with other widgets, like Row or Column:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Now the form only takes up 1/3 of the screen width.
    return Row(children: [
      Expanded(child: Container()),
      Expanded(child: MyForm()),
      Expanded(child: Container()),
    ]);
  }
}

Why does this happen?

@jonahwilliams
Copy link
Member

@kharland is MyWidget the root of your application (i.e. passed to runApp)?

@HansMuller HansMuller added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Nov 20, 2019
@Hixie
Copy link
Contributor

Hixie commented Jan 10, 2020

Form isn't a render object so it has no geometry. You should have the same problem if you just used Column in MyForm directly.

As far as I can tell this is working as intended.

@Hixie Hixie closed this as completed Jan 10, 2020
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

No branches or pull requests

5 participants