Skip to content

Added ExpansionTileController - #123298

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
HansMuller:expansion_tile_controller
Mar 24, 2023
Merged

auto-submit[bot] merged 7 commits into
flutter:masterfrom
HansMuller:expansion_tile_controller

Conversation

@HansMuller

@HansMuller HansMuller commented Mar 22, 2023 •

Copy link
Copy Markdown
Contributor

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 p: material_ui material_ui package in flutter/packages 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
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
@HansMuller
HansMuller force-pushed the expansion_tile_controller branch from c67964f to 0d1c991 Compare March 23, 2023 18:13
@HansMuller

Copy link
Copy Markdown
Contributor Author

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

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated
Comment thread packages/flutter/lib/src/material/expansion_tile.dart Outdated

Copy link
Copy Markdown
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?

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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 framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Programmatically open and close ExpansionTile Widget.

3 participants