Skip to content

Added ExpansionTileController #123298

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

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. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Mar 22, 2023
@HansMuller HansMuller force-pushed the expansion_tile_controller branch from 7b30765 to 228135d Compare March 23, 2023 00:10
@HansMuller HansMuller force-pushed the expansion_tile_controller branch from c67964f to 0d1c991 Compare March 23, 2023 18:13
@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 HansMuller force-pushed the expansion_tile_controller branch from 0d1c991 to f308b66 Compare March 23, 2023 19:21
@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.

@HansMuller HansMuller force-pushed the expansion_tile_controller branch from 0f5fc20 to aa49bff Compare March 23, 2023 20:34
/// 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.

@HansMuller HansMuller force-pushed the expansion_tile_controller branch from aa49bff to 8505e5b Compare March 23, 2023 23:42
@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
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 c: contributor-productivity Team-specific productivity, code health, technical debt. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Programmatically open and close ExpansionTile Widget.
3 participants