-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[material_ui] Add trailingIconVisibility to ExpansionPanel (#179167) #12819
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
Open
benji-farquhar
wants to merge
1
commit into
flutter:main
Choose a base branch
from
benji-farquhar:trailing-icon-visibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
packages/material_ui/example/lib/expansion_panel/expansion_panel_list.1.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| // #region body | ||
| import 'package:material_ui/material_ui.dart'; | ||
|
|
||
| /// Flutter code sample for [ExpansionPanel.trailingIconVisibility]. | ||
|
|
||
| void main() => runApp(const ExpansionPanelIconVisibilityExampleApp()); | ||
|
|
||
| class ExpansionPanelIconVisibilityExampleApp extends StatelessWidget { | ||
| const ExpansionPanelIconVisibilityExampleApp({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| home: Scaffold( | ||
| appBar: AppBar(title: const Text('ExpansionPanel Icon Visibility')), | ||
| body: const ExpansionPanelIconVisibilityExample(), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class ExpansionPanelIconVisibilityExample extends StatefulWidget { | ||
| const ExpansionPanelIconVisibilityExample({super.key}); | ||
|
|
||
| @override | ||
| State<ExpansionPanelIconVisibilityExample> createState() => | ||
| _ExpansionPanelIconVisibilityExampleState(); | ||
| } | ||
|
|
||
| class _ExpansionPanelIconVisibilityExampleState | ||
| extends State<ExpansionPanelIconVisibilityExample> { | ||
| ExpansionPanelIconVisibility _visibility = .visible; | ||
| bool _canTapOnHeader = false; | ||
| final List<bool> _isExpanded = <bool>[false, false, false]; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return SingleChildScrollView( | ||
| child: Column( | ||
| children: <Widget>[ | ||
| const SizedBox(height: 24), | ||
| Padding( | ||
| padding: const EdgeInsets.symmetric(horizontal: 16), | ||
| child: Column( | ||
| children: <Widget>[ | ||
| SegmentedButton<ExpansionPanelIconVisibility>( | ||
| segments: const <ButtonSegment<ExpansionPanelIconVisibility>>[ | ||
| ButtonSegment<ExpansionPanelIconVisibility>( | ||
| value: .visible, | ||
| label: Text('Visible'), | ||
| ), | ||
| ButtonSegment<ExpansionPanelIconVisibility>( | ||
| value: .hidden, | ||
| label: Text('Hidden'), | ||
| ), | ||
| ButtonSegment<ExpansionPanelIconVisibility>( | ||
| value: .gone, | ||
| label: Text('Gone'), | ||
| ), | ||
| ], | ||
|
benji-farquhar marked this conversation as resolved.
|
||
| selected: <ExpansionPanelIconVisibility>{_visibility}, | ||
| onSelectionChanged: | ||
| (Set<ExpansionPanelIconVisibility> selected) { | ||
| setState(() { | ||
| _visibility = selected.first; | ||
| }); | ||
| }, | ||
| ), | ||
| const SizedBox(height: 12), | ||
| SwitchListTile( | ||
| title: const Text('canTapOnHeader'), | ||
| value: _canTapOnHeader, | ||
| onChanged: (bool value) { | ||
| setState(() { | ||
| _canTapOnHeader = value; | ||
| }); | ||
| }, | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| const SizedBox(height: 24), | ||
| ExpansionPanelList( | ||
| expansionCallback: (int index, bool isExpanded) { | ||
| setState(() { | ||
| _isExpanded[index] = isExpanded; | ||
| }); | ||
| }, | ||
| children: <ExpansionPanel>[ | ||
| for (int i = 0; i < 3; i++) | ||
| ExpansionPanel( | ||
| trailingIconVisibility: _visibility, | ||
| canTapOnHeader: _canTapOnHeader, | ||
| headerBuilder: (BuildContext context, bool isExpanded) { | ||
| return ListTile( | ||
| title: Text('Panel ${i + 1}'), | ||
| trailing: Container( | ||
| width: 8, | ||
| height: 8, | ||
| decoration: BoxDecoration( | ||
| color: Theme.of(context).colorScheme.primary, | ||
| shape: BoxShape.circle, | ||
| ), | ||
| ), | ||
| ); | ||
| }, | ||
| body: ListTile( | ||
| title: Text('Panel ${i + 1} content'), | ||
| subtitle: const Text( | ||
| 'When the icon visibility is hidden, the space is preserved. ' | ||
| 'When gone, the space is removed.', | ||
| ), | ||
| ), | ||
| isExpanded: _isExpanded[i], | ||
| ), | ||
| ], | ||
| ), | ||
| const SizedBox(height: 24), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| // #endregion body | ||
42 changes: 42 additions & 0 deletions
42
packages/material_ui/example/test/expansion_panel/expansion_panel_list.1_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:material_ui/material_ui.dart'; | ||
| import 'package:material_ui_examples/expansion_panel/expansion_panel_list.1.dart' | ||
| as example; | ||
|
|
||
| void main() { | ||
| testWidgets('ExpansionPanel icon visibility can be toggled', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| await tester.pumpWidget( | ||
| const example.ExpansionPanelIconVisibilityExampleApp(), | ||
| ); | ||
|
|
||
| expect(find.byType(ExpandIcon), findsNWidgets(3)); | ||
|
|
||
| final Finder visibilityFinder = find | ||
| .ancestor( | ||
| of: find.byType(ExpandIcon).first, | ||
| matching: find.byType(Visibility), | ||
| ) | ||
| .first; | ||
|
|
||
| Visibility visibility = tester.widget(visibilityFinder); | ||
| expect(visibility.visible, isTrue); | ||
|
|
||
| await tester.tap(find.text('Hidden')); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| visibility = tester.widget(visibilityFinder); | ||
| expect(visibility.visible, isFalse); | ||
| expect(visibility.maintainSize, isTrue); | ||
|
|
||
| await tester.tap(find.text('Gone')); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.byType(ExpandIcon), findsNothing); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/material_ui/pending_changelogs/expansion_panel_trailing_icon_visibility.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| changelog: | | ||
| - Adds `ExpansionPanel.trailingIconVisibility` to control expand/collapse icon visibility. | ||
| version: minor |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.