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

Added ExpansionTileController #123298

Merged
merged 7 commits into from Mar 24, 2023

Conversation

HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Mar 22, 2023

Supports programmatically expanding or collapsing an ExpansionTile.

Most of the work for this PR was completed by @xvrh in #107038.

Fixes #60387

Here's an example:

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final ExpansionTileController controller = ExpansionTileController();

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        ExpansionTile(
          controller: controller,
          title: const Text('Collapsible menu'),
          children: const <Widget>[
            Text('Menu'),
          ],
        ),
        ElevatedButton(
          onPressed: () {
            if (controller.isExpanded) {
              controller.collapse();
            } else {
              controller.expand();
            }
          },
          child: const Text('TOGGLE MENU'),
        )
      ],
    );
  }
}

@flutter-dashboard flutter-dashboard bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. labels Mar 22, 2023
@HansMuller
Copy link
Contributor Author

This PR doesn't include something comparable to ExpansionTile.of(context) from #107038; I will add ExpansionTileController.of(context).

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

I will add ExpansionTileController.of(context).

Did you want to do that in this PR or in a separate one?

@HansMuller
Copy link
Contributor Author

I've added ExpansionController.of,maybeOf to this PR. Should be ready for review.

/// to provide a new scope with a [BuildContext] that is "under" the
/// [ExpansionTile]:
///
/// ** See code in examples/api/lib/material/expansion_tile/expansion_tile.of.1.dart **
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same sample back to back, is that intended?

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pull from remote before adding ore commits. I fixed typos before and now to try to be helpful.

/// to provide a new scope with a [BuildContext] that is "under" the
/// [ExpansionTile]:
///
/// ** See code in examples/api/lib/material/expansion_tile/expansion_tile.1.dart **
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still the same sample back to back, is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The sample covers both topics.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to have it shown once, and discuss the two cases together? Otherwise when you read the first one, half of the code has no context, and then when you read it again the second time it appears, it makes full sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean, yes. Merged the doc.

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 23, 2023
@auto-submit auto-submit bot merged commit 59c9d4e into flutter:master Mar 24, 2023
71 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2023
@hadi7khan
Copy link

what about list of ExpansionTile? How to pass different controllers n control expand close for every tile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Programmatically open and close ExpansionTile Widget.
3 participants