-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Expose ExpansionTileState #107038
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
Expose ExpansionTileState #107038
Conversation
|
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
@xvrh This patch looks fantastic, sorry it took us so long to look at it. Would you mind rebasing it and force pushing an update? That will cause the tests to restart, so we can see an up to date status. |
Allows to programmatically expand or collapse an ExpansionTile
0dfd996 to
744a9fc
Compare
|
@Hixie I rebased the branch. |
|
+1 this PR |
|
I've been reluctant to review this PR because it's generally not a good idea to turn a State object into public API, since State has many methods that aren't relevant in a case like this. Usually, we've dealt with this case by creating a class like ExpansionTileController that the developer can pass to a ExpansionTile and that exposes only as much API as is needed. |
|
@HansMuller understood! I will try with the |
|
I'll close this PR and reopen a new one when I have time to work on the |
|
@xvrh - there are have been some additional requests for this feature so I'm going to try and land an ExpansionTileController version shortly. What I'm planning is very similar to what you've done, except that the controller's API will be limited to isExpanded, expand() and collapse(): 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'),
)
],
);
}
}This really is the same thing under the hood, so an ExpansionTileController can only control one ExpansionTile. |
Allows to programmatically expand or collapse an ExpansionTile
Fixes #60387
Example usage:
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.